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

No close() function is called for recvNotifyCh in Stream? #13

Closed
QiangYuzhou opened this issue Jan 20, 2020 · 2 comments
Closed

No close() function is called for recvNotifyCh in Stream? #13

QiangYuzhou opened this issue Jan 20, 2020 · 2 comments
Labels
kind/support A question or request for support

Comments

@QiangYuzhou
Copy link

The chan struct{} in Stream, such as recvNotifyCh, sendNotifyCh, readDeadline, writeDeadline, is never closed?
The problem is that: In server I call Host.NewStream (in go-libp2p-core) to get a stream, and write something to this stream, then close the stream. The client will receive this message and output it in the console, close too.
However, the memory continues growing, and I use pprof to test why this happens, and the memory occupied by the channels is large and still growing.
I try to output the size of session.streams, and it is 2 all the time. It means the stream is actually deleted in this map(id->Stream).
Then I try to add close(recvNotifyCh) in cleanup function in stream.go. However, one error occurs: send on closed channel, because asyncNotify is called after the cleanup function.
The channels in Stream seem not to be moved by GC. And I'd like to know how to fix it? What's the reason? or there are some problems in my code, and how should I use libp2p correctly?
Thanks for your apply!

@Stebalien
Copy link
Member

Libp2p streams are half-open and Close is really CloseWrite (for now). At the moment, to fully close a stream, you need to either:

  1. Reset the stream. Note: this will drop any pending writes.
  2. Read an EOF on the stream. That is, observe that the other side has closed the stream.

There are some helpers (FullClose and AwaitEOF) in https://godoc.org/github.com/libp2p/go-libp2p-core/helpers to help with this.

(there's also a patch that has been under discussion for a while to fix this: libp2p/go-libp2p-core#10)

@Stebalien Stebalien added the kind/support A question or request for support label Jan 20, 2020
@QiangYuzhou
Copy link
Author

Libp2p streams are half-open and Close is really CloseWrite (for now). At the moment, to fully close a stream, you need to either:

  1. Reset the stream. Note: this will drop any pending writes.
  2. Read an EOF on the stream. That is, observe that the other side has closed the stream.

There are some helpers (FullClose and AwaitEOF) in https://godoc.org/github.com/libp2p/go-libp2p-core/helpers to help with this.

(there's also a patch that has been under discussion for a while to fix this: libp2p/go-libp2p-core#10)

Thanks a lot! It really works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

2 participants