diff --git a/SOURCES/bz1512586-galera-recover-from-empty-gvwstate.dat.patch b/SOURCES/bz1512586-galera-recover-from-empty-gvwstate.dat.patch
new file mode 100644
index 0000000..0d6f6aa
--- /dev/null
+++ b/SOURCES/bz1512586-galera-recover-from-empty-gvwstate.dat.patch
@@ -0,0 +1,40 @@
+From 8fef58405fbac15c0ea93f0d890b114c870de0cc Mon Sep 17 00:00:00 2001
+From: Damien Ciabrini <dciabrin@redhat.com>
+Date: Wed, 8 Nov 2017 15:19:33 +0100
+Subject: [PATCH] galera: recover from empty gvwstate.dat
+
+While running, a galera node keeps track of the last known state of
+the cluster in a temporary file gvwstate.dat. This file is normally
+deleted once a node is shutdown gracefully.
+
+Some ungraceful shutdowns can leave an empty gvwstate.dat on
+disk. This will prevent galera to join the cluster if it is
+configured to attempt PC recovery. Removing that file makes the
+node fall back to the normal, unoptimized joining process next
+time it is restarted.
+---
+ heartbeat/galera | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/heartbeat/galera b/heartbeat/galera
+index ab121a4be..ee8451427 100755
+--- a/heartbeat/galera
++++ b/heartbeat/galera
+@@ -586,6 +586,17 @@ detect_last_commit()
+     local recovery_file_regex='s/.*WSREP\:.*position\s*recovery.*--log_error='\''\([^'\'']*\)'\''.*/\1/p'
+     local recovered_position_regex='s/.*WSREP\:\s*[R|r]ecovered\s*position.*\:\(.*\)\s*$/\1/p'
+ 
++    # codership/galera#354
++    # Some ungraceful shutdowns can leave an empty gvwstate.dat on
++    # disk. This will prevent galera to join the cluster if it is
++    # configured to attempt PC recovery. Removing that file makes the
++    # node fall back to the normal, unoptimized joining process.
++    if [ -f ${OCF_RESKEY_datadir}/gvwstate.dat ] && \
++       [ ! -s ${OCF_RESKEY_datadir}/gvwstate.dat ]; then
++        ocf_log warn "empty ${OCF_RESKEY_datadir}/gvwstate.dat detected, removing it to prevent PC recovery failure at next restart"
++        rm -f ${OCF_RESKEY_datadir}/gvwstate.dat
++    fi
++
+     ocf_log info "attempting to detect last commit version by reading ${OCF_RESKEY_datadir}/grastate.dat"
+     last_commit="$(cat ${OCF_RESKEY_datadir}/grastate.dat | sed -n 's/^seqno.\s*\(.*\)\s*$/\1/p')"
+     if [ -z "$last_commit" ] || [ "$last_commit" = "-1" ]; then
diff --git a/SPECS/resource-agents.spec b/SPECS/resource-agents.spec
index e7b499a..3915ce7 100644
--- a/SPECS/resource-agents.spec
+++ b/SPECS/resource-agents.spec
@@ -48,7 +48,7 @@
 Name:		resource-agents
 Summary:	Open Source HA Reusable Cluster Resource Scripts
 Version:	3.9.5
-Release:	105%{?dist}.2
+Release:	105%{?dist}.3
 License:	GPLv2+, LGPLv2+ and ASL 2.0
 URL:		https://github.com/ClusterLabs/resource-agents
 %if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel}
@@ -238,6 +238,7 @@ Patch177:	bz1342376-3-rabbitmq-cluster-backup-and-restore-users-policies.patch
 Patch178:	bz1493915-1-support-per-host-per-bundle-attribs.patch
 Patch179:	bz1493915-2-support-per-host-per-bundle-attribs.patch
 Patch180:	bz1497076-NovaEvacuate-Instance-HA-OSP12.patch
+Patch181:	bz1512586-galera-recover-from-empty-gvwstate.dat.patch
 
 Obsoletes:	heartbeat-resources <= %{version}
 Provides:	heartbeat-resources = %{version}
@@ -533,6 +534,7 @@ exit 1
 %patch178 -p1
 %patch179 -p1 -F2
 %patch180 -p1
+%patch181 -p1
 
 %build
 if [ ! -f configure ]; then
@@ -796,6 +798,11 @@ ccs_update_schema > /dev/null 2>&1 ||:
 %endif
 
 %changelog
+* Mon Nov 13 2017 Oyvind Albrigtsen <oalbrigt@redhat.com> - 3.9.5-105.3
+- galera: recover from empty gvwstate.dat
+
+  Resolves: rhbz#1512586
+
 * Fri Sep 29 2017 Oyvind Albrigtsen <oalbrigt@redhat.com> - 3.9.5-105.2
 - NovaEvacuate: changes to support Instance HA on OSP12