Skip to content

Fix createChannel wrongly recreating an already-running network - #1446

Open
wakqasahmed wants to merge 1 commit into
hyperledger:mainfrom
wakqasahmed:fix/createchannel-container-count-1243
Open

wakqasahmed wants to merge 1 commit into
hyperledger:mainfrom
wakqasahmed:fix/createchannel-container-count-1243

Conversation

@wakqasahmed

Copy link
Copy Markdown

Fixes #1243.

createChannel() decides whether the network is already up by counting running hyperledger/-prefixed containers and treating fewer than 4 as "not running". That threshold was correct back in 2022 (#641, when a persistent cli container was still part of the default network) but the default network today only launches 3 (orderer + 2 peers) - the cli container's gone. So createChannel always sees 3 < 4, decides the network isn't up, and calls networkUp() again - which doesn't inherit -s couchdb from the original up command, so it silently overwrites the running CouchDB-backed network with a fresh LevelDB one, exactly as reported.

I verified this against real containers rather than just reasoning from the compose files: reproduced with ./network.sh up -s couchdb followed by a separate ./network.sh createChannel -c mychannel - confirmed the peers get Recreated, couchdb0/couchdb1 end up orphaned, and the log switches to using database leveldb. With the threshold corrected to 3, the same steps now print Network Running Already and leave the running containers untouched.

Fixed both occurrences of the stale 4 - the count check that decides whether to bring the network down to resync certs (line 337) has the same assumption baked in and would stay broken if only the reported line were changed.

@wakqasahmed
wakqasahmed requested a review from a team as a code owner September 3, 2026 12:34
Refs hyperledger#1243. createChannel() decides whether the network is already up by
counting running hyperledger/-prefixed containers and treating fewer
than 4 as 'not running'. That threshold was correct in 2022 (hyperledger#641, back
when a persistent cli container was also part of the default network),
but the default network today only launches 3 (orderer + 2 peers) - the
cli container is gone. So createChannel always sees 3 < 4, decides the
network isn't up, and brings it up again via networkUp(), which does not
inherit -s couchdb from the original up command - overwriting the running
CouchDB-backed network with a fresh LevelDB one.

Verified against real containers, not just reasoning from the compose
files: reproduced with ./network.sh up -s couchdb followed by a separate
./network.sh createChannel -c mychannel - confirmed the peers get
Recreated, couchdb0/couchdb1 are orphaned, and the log switches to
'using database leveldb'. With the threshold corrected to 3 (both the
count check on line 337 and the bring-up decision on line 342, which
share the same stale assumption), the same steps now print 'Network
Running Already' and the existing containers are left untouched.

Signed-off-by: wakqasahmed <wakqasahmed@gmail.com>
@wakqasahmed

Copy link
Copy Markdown
Author

Hi @bestbeforetoday — not sure who owns review for this one — it's been a little while, green and mergeable. Could you take a look or redirect me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test network incorrectly recreates a fabric network when creating a channel

1 participant