Reorder commands as Marco noted:

```
This could throw an OOM. We should do:

Create MultiConnection (can error)
dlist_push_tail (can error)
sharedCounterIncremented = true (cannot error)
increment the shared memory counter (cannot error)
any error after this will be handled correctly in the abort handler
```
preventConflictingFlags
Onder Kalaci 2020-04-08 17:39:07 +02:00
parent eadb18e758
commit af587edea1
1 changed files with 11 additions and 8 deletions

View File

@ -320,6 +320,14 @@ StartNodeUserDatabaseConnection(uint32 flags, const char *hostname, int32 port,
} }
/*
* Either no caching desired, or no pre-established, non-claimed,
* connection present. Initiate connection establishment.
*/
MultiConnection *connection = MemoryContextAllocZero(ConnectionContext,
sizeof(MultiConnection));
dlist_push_tail(entry->connections, &connection->connectionNode);
if (flags & WAIT_FOR_CONNECTION) if (flags & WAIT_FOR_CONNECTION)
{ {
WaitLoopForSharedConnection(hostname, port); WaitLoopForSharedConnection(hostname, port);
@ -351,18 +359,13 @@ StartNodeUserDatabaseConnection(uint32 flags, const char *hostname, int32 port,
IncrementSharedConnectionCounter(hostname, port); IncrementSharedConnectionCounter(hostname, port);
} }
/* /*
* Either no caching desired, or no pre-established, non-claimed, * We've already incremented the counter above, so we should decrement
* connection present. Initiate connection establishment. * when we're done with the connection.
*/ */
MultiConnection *connection = MemoryContextAllocZero(ConnectionContext,
sizeof(MultiConnection));
/* we've already incremented the counter above */
connection->sharedCounterIncremented = true; connection->sharedCounterIncremented = true;
dlist_push_tail(entry->connections, &connection->connectionNode);
StartConnectionEstablishment(connection, &key); StartConnectionEstablishment(connection, &key);
ResetShardPlacementAssociation(connection); ResetShardPlacementAssociation(connection);