using go routine in the chaincode #fabric-questions #fabric-chaincode


Concurrency (using goroutine and go channel) can cause non-deterministic behavior in fabric.

I have not found any source or example on the use of Goroutines and go channels in fabric contracts; I need an example; Are there any links that I can read about it?.

I know that it is better not to use the following code, but I want to know how the race condition that is in the code causes inconsistency among peers.
I appritiate any help.

package main import (





type BadChainCode struct{


func (t *BadChainCode) Invoke(stub shim.ChaincodeStubInterface){

go writeToLedger(stub, “data1”)

go writeToLedger(stub, “data2”)


func writeToLedger(stub shim.ChaincodeStubInterface, data string){



Join to automatically receive all group messages.