Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream deadlock #7

Closed
lukesolo opened this issue Oct 22, 2019 · 4 comments · Fixed by #8
Closed

Stream deadlock #7

lukesolo opened this issue Oct 22, 2019 · 4 comments · Fixed by #8
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@lukesolo
Copy link

I've got a deadlock using Stream

goroutine 1 took s.recvLock.Lock() and then s.stateLock.Lock()
goroutine 2 took s.stateLock.Lock() and then s.recvLock.Lock()

#	0x4431a6	sync.runtime_SemacquireMutex+0x46							/usr/local/go/src/runtime/sema.go:71
#	0x46f32b	sync.(*Mutex).lockSlow+0xfb								/usr/local/go/src/sync/mutex.go:138
#	0xa3e8a9	sync.(*Mutex).Lock+0xd9									/usr/local/go/src/sync/mutex.go:81
#	0xa3e80c	github.com/libp2p/go-yamux.(*Stream).sendFlags+0x3c					/go/pkg/mod/github.com/libp2p/[email protected]/stream.go:194
#	0xa3e92d	github.com/libp2p/go-yamux.(*Stream).sendWindowUpdate+0x6d				/go/pkg/mod/github.com/libp2p/[email protected]/stream.go:217
#	0xa3df49	github.com/libp2p/go-yamux.(*Stream).Read+0x2c9						/go/pkg/mod/github.com/libp2p/[email protected]/stream.go:109
#	0xe0e640	github.com/libp2p/go-libp2p-swarm.(*Stream).Read+0x60					/go/pkg/mod/github.com/libp2p/[email protected]/swarm_stream.go:64
#	0xd316e7	github.com/multiformats/go-multistream.(*lazyClientConn).Read+0xa7			/go/pkg/mod/github.com/multiformats/[email protected]/lazyClient.go:75
#	0xddeb31	github.com/libp2p/go-libp2p/p2p/host/basic.(*streamWrapper).Read+0x51			/go/pkg/mod/github.com/libp2p/[email protected]/p2p/host/basic/basic_host.go:765
...

#	0x4431a6	sync.runtime_SemacquireMutex+0x46					/usr/local/go/src/runtime/sema.go:71
#	0x46f32b	sync.(*Mutex).lockSlow+0xfb						/usr/local/go/src/sync/mutex.go:138
#	0xa3e09c	sync.(*Mutex).Lock+0x41c						/usr/local/go/src/sync/mutex.go:81
#	0xa3dd54	github.com/libp2p/go-yamux.(*Stream).Read+0xd4				/go/pkg/mod/github.com/libp2p/[email protected]/stream.go:84
#	0xe0e640	github.com/libp2p/go-libp2p-swarm.(*Stream).Read+0x60			/go/pkg/mod/github.com/libp2p/[email protected]/swarm_stream.go:64
#	0xd316e7	github.com/multiformats/go-multistream.(*lazyClientConn).Read+0xa7	/go/pkg/mod/github.com/multiformats/[email protected]/lazyClient.go:75
#	0xddeb31	github.com/libp2p/go-libp2p/p2p/host/basic.(*streamWrapper).Read+0x51	/go/pkg/mod/github.com/libp2p/[email protected]/p2p/host/basic/basic_host.go:765
#	0xd1ddb1	github.com/libp2p/go-libp2p-core/helpers.AwaitEOF+0xb1			/go/pkg/mod/github.com/libp2p/[email protected]/helpers/stream.go:46
#	0xd1dcd7	github.com/libp2p/go-libp2p-core/helpers.FullClose+0x97			/go/pkg/mod/github.com/libp2p/[email protected]/helpers/stream.go:30
...
@vyzo vyzo added the kind/bug A bug in existing code (including security flaws) label Oct 22, 2019
@Stebalien
Copy link
Member

Damn. Nice catch!

@Stebalien
Copy link
Member

Hm. Although, this raises a good question. Why do we have multiple readers here?

@lukesolo
Copy link
Author

Thanks for fixing it!
I've found that I'm calling full close on stream concurrently with reading from it, so I think it was the cause.

@Stebalien
Copy link
Member

Got it. In this case, just call Close. The point of FullClose is to wait to read an EOF. However, if you're already reading from the stream, there's no point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants