Skip to content

Commit 411cd27

Browse files
committed
fix(set-up): prevent race condition when registering member
1 parent f6e39cd commit 411cd27

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

set-up-process.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# process and is only used to implement a scalable service architecture.
66

77
# Wait until primary node is ready
8-
/wait-for-host.sh couchdb1 && /wait-for-it.sh couchdb1:5984 -t 300
8+
/wait-for-host.sh couchdb1 && /wait-for-it.sh couchdb1:5984 -t 300 && /wait-for-it.sh couchdb1:5986 -t 300
99

1010
if [ $TASK_SLOT -eq 1 ]; then
1111
echo "Setting up primary node..."
@@ -22,8 +22,12 @@ else
2222
echo "Setting up secondary node..."
2323

2424
# Wait until secondary node is ready
25-
/wait-for-host.sh couchdb$TASK_SLOT && /wait-for-it.sh couchdb$TASK_SLOT:5984 -t 300
25+
/wait-for-host.sh couchdb$TASK_SLOT && /wait-for-it.sh couchdb$TASK_SLOT:5984 -t 300 && /wait-for-it.sh couchdb$TASK_SLOT:5986 -t 300
2626

27-
# Register membership
28-
curl -X PUT http://$COUCHDB_USER:$COUCHDB_PASSWORD@couchdb1:5986/_nodes/couchdb@couchdb$TASK_SLOT -d {}
27+
# Register membership. We need to register couchdb1 with this node (couchdb$TASK_SLOT) and not
28+
# vise-versa as this way, we can use `/wait-for-host.sh couchdb1` to guarantee that we have a
29+
# clear route to couchdb1. Otherwise, if we try establishing the membership in the other
30+
# direction, a race condition in the /etc/hosts entries could lead to couchdb1 not being able to
31+
# connect to this node.
32+
curl -X PUT http://$COUCHDB_USER:$COUCHDB_PASSWORD@couchdb$TASK_SLOT:5986/_nodes/couchdb@couchdb1 -d {}
2933
fi

0 commit comments

Comments
 (0)