Skip to content

Commit d8c1ab8

Browse files
committed
This commit fixes potential coordinator crash if no GTM connection
is established. Posted by Wang Diancheng. Reviewed by Koichi Suzuki.
1 parent 4b6db31 commit d8c1ab8

File tree

1 file changed

+16
-11
lines changed
  • src/backend/access/transam

1 file changed

+16
-11
lines changed

src/backend/access/transam/gtm.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,13 @@ BeginTranAutovacuumGTM(void)
170170
int
171171
CommitTranGTM(GlobalTransactionId gxid)
172172
{
173-
int ret;
173+
int ret = -1;
174174

175175
if (!GlobalTransactionIdIsValid(gxid))
176176
return 0;
177177
CheckConnection();
178-
ret = commit_transaction(conn, gxid);
178+
if (conn)
179+
ret = commit_transaction(conn, gxid);
179180

180181
/*
181182
* If something went wrong (timeout), try and reset GTM connection.
@@ -203,12 +204,13 @@ CommitTranGTM(GlobalTransactionId gxid)
203204
int
204205
CommitPreparedTranGTM(GlobalTransactionId gxid, GlobalTransactionId prepared_gxid)
205206
{
206-
int ret = 0;
207+
int ret = -1;
207208

208209
if (!GlobalTransactionIdIsValid(gxid) || !GlobalTransactionIdIsValid(prepared_gxid))
209210
return ret;
210211
CheckConnection();
211-
ret = commit_prepared_transaction(conn, gxid, prepared_gxid);
212+
if (conn)
213+
ret = commit_prepared_transaction(conn, gxid, prepared_gxid);
212214

213215
/*
214216
* If something went wrong (timeout), try and reset GTM connection.
@@ -257,13 +259,14 @@ StartPreparedTranGTM(GlobalTransactionId gxid,
257259
char *gid,
258260
char *nodestring)
259261
{
260-
int ret = 0;
262+
int ret = -1;
261263

262264
if (!GlobalTransactionIdIsValid(gxid))
263265
return 0;
264266
CheckConnection();
265267

266-
ret = start_prepared_transaction(conn, gxid, gid, nodestring);
268+
if (conn)
269+
ret = start_prepared_transaction(conn, gxid, gid, nodestring);
267270

268271
/*
269272
* If something went wrong (timeout), try and reset GTM connection.
@@ -282,12 +285,13 @@ StartPreparedTranGTM(GlobalTransactionId gxid,
282285
int
283286
PrepareTranGTM(GlobalTransactionId gxid)
284287
{
285-
int ret;
288+
int ret = -1;
286289

287290
if (!GlobalTransactionIdIsValid(gxid))
288291
return 0;
289292
CheckConnection();
290-
ret = prepare_transaction(conn, gxid);
293+
if (conn)
294+
ret = prepare_transaction(conn, gxid);
291295

292296
/*
293297
* If something went wrong (timeout), try and reset GTM connection.
@@ -310,11 +314,12 @@ GetGIDDataGTM(char *gid,
310314
GlobalTransactionId *prepared_gxid,
311315
char **nodestring)
312316
{
313-
int ret = 0;
317+
int ret = -1;
314318

315319
CheckConnection();
316-
ret = get_gid_data(conn, GTM_ISOLATION_RC, gid, gxid,
317-
prepared_gxid, nodestring);
320+
if (conn)
321+
ret = get_gid_data(conn, GTM_ISOLATION_RC, gid, gxid,
322+
prepared_gxid, nodestring);
318323

319324
/*
320325
* If something went wrong (timeout), try and reset GTM connection.

0 commit comments

Comments
 (0)