SIGBlockchain / project_aurum

SIG Blockchain blockchain project in Go
https://acm.cs.uic.edu/sigblockchain
MIT License
7 stars 1 forks source link

Go routine in TestContractRequestHandler #341

Closed HarryL5004 closed 4 years ago

HarryL5004 commented 4 years ago

Issue #325

kastolars commented 4 years ago

What happened to using WaitGroup?

HarryL5004 commented 4 years ago

If waitgroup is used in cmd main.go, the waitgroup counter can go negative and panic.

kastolars commented 4 years ago

Why would we need one in main.go? The issue just concerns the test function.

HarryL5004 commented 4 years ago

That's because a wait group instance must be passed into the contract handler to signal the waitgroup that this goroutine is done, and main.go initiate a contract handler.

kastolars commented 4 years ago

Hm. Can you do something like

var waitgroup sync.WaitGroup
waitgroup.Add(1)
go func(){
    handler.ServeHTTP(rr, tt.req)
    waitgroup.Done()
}()
waitgroup.Wait()
kastolars commented 4 years ago

I don't think it's a great idea to edit so many files for this issue, I'd almost rather just have the 1 second sleep at that point. But there's gotta be a way to use a WaitGroup to achieve this.

kastolars commented 4 years ago

Interesting, do you know why increasing the cap makes it work? I'm curious

HarryL5004 commented 4 years ago

Previously the channel blocks all processes until there's a receiver retrieving the contract in the channel. By increasing the capacity, the channel will only start to block processes when it is full. If the channel is never full, it will never block any processes.