Skip to content

handle timeouts using i/o deadlines.#48

Open
raulk wants to merge 1 commit intomasterfrom
fix/timeout
Open

handle timeouts using i/o deadlines.#48
raulk wants to merge 1 commit intomasterfrom
fix/timeout

Conversation

@raulk
Copy link
Member

@raulk raulk commented Nov 1, 2019

Both initiator and responder now time out if reads and/or writes are blocked for 30 seconds (default negotiation timeout).

Introduces two tests to validate the new behaviour.

Fixes #47.
Addresses filecoin-project/lotus#518.

Both initiator and responder now time out if reads
and/or writes are blocked for 30 seconds (default
negotiation timeout).

Introduces two tests to validate the new behaviour.

Fixes #47.
@raulk
Copy link
Member Author

raulk commented Nov 1, 2019

This fails CI because of libp2p/go-libp2p#736.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: IMO, the real issue is libp2p/go-libp2p#738.

(although canceling here as well is probably a good idea anyways)

}
if err2 != nil {
return err2
if clearFn, err := setDeadline(rwc); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, many connections implement net.Conn (and SetDeadline) but don't actually implement it (and instead return an error). This is why we do things like https://github.com/libp2p/go-libp2p-transport-upgrader/blob/0d4065ec7151149beef41f3a8b1fbf6978ed12dc/upgrader.go#L111-L132.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we could detect and handle os.ErrNoDeadline.

"time"
)

// NegotiationTimeout is the maximum time a protocol negotiation atempt is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/atempt/attempt

lidel added a commit to libp2p/go-libp2p that referenced this pull request Jan 7, 2026
…t blocking

streamWrapper.Close() can block indefinitely when the remote peer is slow
or unresponsive during the multistream-select handshake completion.

The lazy multistream protocol negotiation defers reading the handshake
response until Close() is called. If the remote peer doesn't respond,
the read blocks forever, causing goroutine leaks.

This is particularly problematic for bitswap servers where taskWorkers
can get stuck trying to close streams after sending blocks.

The fix sets a read deadline (using DefaultNegotiationTimeout) before
calling the multistream Close(), ensuring the operation will time out
rather than block indefinitely.

Related: multiformats/go-multistream#47
Related: multiformats/go-multistream#48
lidel added a commit to libp2p/go-libp2p that referenced this pull request Jan 7, 2026
…t blocking

streamWrapper.Close() can block indefinitely when the remote peer is slow
or unresponsive during the multistream-select handshake completion.

The lazy multistream protocol negotiation defers reading the handshake
response until Close() is called. If the remote peer doesn't respond,
the read blocks forever, causing goroutine leaks.

This is particularly problematic for bitswap servers where taskWorkers
can get stuck trying to close streams after sending blocks.

The fix sets a read deadline (using DefaultNegotiationTimeout) before
calling the multistream Close(), ensuring the operation will time out
rather than block indefinitely.

Related: multiformats/go-multistream#47
Related: multiformats/go-multistream#48
MarcoPolo pushed a commit to libp2p/go-libp2p that referenced this pull request Jan 7, 2026
…t blocking

streamWrapper.Close() can block indefinitely when the remote peer is slow
or unresponsive during the multistream-select handshake completion.

The lazy multistream protocol negotiation defers reading the handshake
response until Close() is called. If the remote peer doesn't respond,
the read blocks forever, causing goroutine leaks.

This is particularly problematic for bitswap servers where taskWorkers
can get stuck trying to close streams after sending blocks.

The fix sets a read deadline (using DefaultNegotiationTimeout) before
calling the multistream Close(), ensuring the operation will time out
rather than block indefinitely.

Related: multiformats/go-multistream#47
Related: multiformats/go-multistream#48
MarcoPolo pushed a commit to libp2p/go-libp2p that referenced this pull request Jan 8, 2026
…t blocking

streamWrapper.Close() can block indefinitely when the remote peer is slow
or unresponsive during the multistream-select handshake completion.

The lazy multistream protocol negotiation defers reading the handshake
response until Close() is called. If the remote peer doesn't respond,
the read blocks forever, causing goroutine leaks.

This is particularly problematic for bitswap servers where taskWorkers
can get stuck trying to close streams after sending blocks.

The fix sets a read deadline (using DefaultNegotiationTimeout) before
calling the multistream Close(), ensuring the operation will time out
rather than block indefinitely.

Related: multiformats/go-multistream#47
Related: multiformats/go-multistream#48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multistream-select v1 does not handle timeouts

4 participants