Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Make conn.Close() wait till shutdown is complete. #203

Closed
wants to merge 1 commit into from

Conversation

alanconway
Copy link
Contributor

This showed up with the improved logging: log messages for the Close frames of one
test were printed after another test had started.

Should be deadlock safe, since we don't call user callbacks in the mux or tx/rx goroutines.

Signed-off-by: Alan Conway aconway@redhat.com

@vcabbage
Copy link
Owner

vcabbage commented Dec 5, 2019

conn.errMu is supposed to be held by conn.mux until the connection is closed and all other goroutines have exited. It doesn't return until conn.close runs. conn.close closes conn.done and waits for conn.txDone and conn.rxDone.

conn.Close waits for conn.errMu via conn.getErr.

Perhaps conn.Close -> conn.getErr raced with conn.mux and acquired conn.errMu first. It's nicer to pair them up but for correctness it seems c.errMu.Lock() needs to happen before the mux goroutine is started.

amqp/conn.go

Lines 339 to 342 in ae5d459

// hold the errMu lock until error or done
c.errMu.Lock()
defer c.errMu.Unlock()
defer c.close() // defer order is important. c.errMu unlock indicates that connection is finally complete

alanconway added a commit to alanconway/vcabbage-amqp that referenced this pull request Dec 5, 2019
example_server_test.go: very simple one-queue broker, tests basic send/receive.

- Lots of unfinished stuff: grep for FIXME to see known holes.
- Needs much more testing, performance profiling etc.

Depends on the following pending PRs, must be re-based after they merge:

- vcabbage#204  Improved debug logging.
- vcabbage#203  Make conn.Close() wait till shutdown is complete.
- vcabbage#201  Rename Client to Conn
- vcabbage#198  Fix SEGV when using dynamic addresses.

Signed-off-by: Alan Conway <aconway@redhat.com>
@vcabbage vcabbage mentioned this pull request Dec 9, 2019
@alanconway
Copy link
Contributor Author

I don't think you need the mutex at all (and I wouldn't lock/unlock a mutex in different functions)
All the error checks are already guarded by a <-done check, so if you just set the error before close(c.done) you can access safely using only the channels Patch coming...

@alanconway
Copy link
Contributor Author

This version drops the mutex, fixes the out-of-order logging and passes go test -race.

This showed up with the improved logging: log messages for the Close frames of one
test were printed after another test had started.

Should be deadlock safe, since we don't call user callbacks in the mux or tx/rx goroutines.

Signed-off-by: Alan Conway <aconway@redhat.com>
@vcabbage
Copy link
Owner

I was only going to accept this because it should have been a small fix. While you may well be correct, I'm not accepting any refactors.

@vcabbage vcabbage closed this Dec 10, 2019
alanconway added a commit to alanconway/vcabbage-amqp that referenced this pull request Dec 11, 2019
example_server_test.go: very simple one-queue broker, tests basic send/receive.

- Lots of unfinished stuff: grep for FIXME to see known holes.
- Needs much more testing, performance profiling etc.

Depends on the following pending PRs, must be re-based after they merge:

- vcabbage#204  Improved debug logging.
- vcabbage#203  Make conn.Close() wait till shutdown is complete.
- vcabbage#201  Rename Client to Conn
- vcabbage#198  Fix SEGV when using dynamic addresses.

Signed-off-by: Alan Conway <aconway@redhat.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants