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

fix: Set missing deadlines #2794

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions p2p/net/gostream/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package gostream
import (
"context"
"net"
"time"

"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/protocol"
)

var ServerTimeout = 60 * time.Second

// listener is an implementation of net.Listener which handles
// http-tagged streams from a libp2p connection.
// A listener can be built with Listen()
Expand Down Expand Up @@ -60,6 +63,7 @@ func Listen(h host.Host, tag protocol.ID) (net.Listener, error) {
}

h.SetStreamHandler(tag, func(s network.Stream) {
s.SetDeadline(time.Now().Add(ServerTimeout))
MarcoPolo marked this conversation as resolved.
Show resolved Hide resolved
select {
case l.streamCh <- s:
case <-ctx.Done():
Expand Down
2 changes: 2 additions & 0 deletions p2p/protocol/circuitv2/client/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (c *Client) handleStreamV2(s network.Stream) {
defer rd.Close()

writeResponse := func(status pbv2.Status) error {
s.SetWriteDeadline(time.Now().Add(StreamTimeout))
defer s.SetWriteDeadline(time.Time{})
wr := util.NewDelimitedWriter(s)

var msg pbv2.StopMessage
Expand Down
2 changes: 2 additions & 0 deletions p2p/protocol/circuitv2/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ func (r *Relay) handleError(s network.Stream, status pbv2.Status) {
}

func (r *Relay) writeResponse(s network.Stream, status pbv2.Status, rsvp *pbv2.Reservation, limit *pbv2.Limit) error {
s.SetWriteDeadline(time.Now().Add(StreamTimeout))
defer s.SetWriteDeadline(time.Time{})
wr := util.NewDelimitedWriter(s)

var msg pbv2.HopMessage
Expand Down
Loading