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

debug interop failure #2588

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 18 additions & 30 deletions p2p/protocol/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,29 @@ func (p *PingService) PingHandler(s network.Stream) {

buf := pool.Get(PingSize)
defer pool.Put(buf)
defer s.Close()

errCh := make(chan error, 1)
defer close(errCh)
timer := time.NewTimer(pingTimeout)
defer timer.Stop()

go func() {
select {
case <-timer.C:
log.Debug("ping timeout")
case err, ok := <-errCh:
if ok {
log.Debug(err)
} else {
log.Error("ping loop failed without error")
}
}
s.Close()
}()

for {
_, err := io.ReadFull(s, buf)
if err != nil {
errCh <- err
return
}

_, err = s.Write(buf)
if err != nil {
errCh <- err
return
}
_, err := io.ReadFull(s, buf)
if err != nil {
errCh <- err
return
}
log.Errorln("first read done")
st := time.Now()
_, err = io.ReadFull(s, buf)
if err != nil {
log.Errorln("exiting", err, time.Since(st))
return
}

timer.Reset(pingTimeout)
_, err = s.Write(buf)
if err != nil {
errCh <- err
return
}
time.Sleep(5 * time.Second)
}

// Result is a result of a ping attempt, either an RTT or an error.
Expand Down
20 changes: 3 additions & 17 deletions p2p/transport/webrtc/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,7 @@ func newStream(
}
}

if s.isDone() {
// onDone removes the stream from the connection and requires the connection lock.
// This callback(onBufferedAmountLow) is executing in the sctp readLoop goroutine.
// If Connection.Close is called concurrently, the closing goroutine will acquire
// the connection lock and wait for sctp readLoop to exit, the sctp readLoop will
// wait for the connection lock before exiting, causing a deadlock.
// Run this in a different goroutine to avoid the deadlock.
go func() {
s.mx.Lock()
defer s.mx.Unlock()
// TODO: we should be closing the underlying datachannel, but this resets the stream
// See https://github.com/libp2p/specs/issues/575 for details.
// _ = s.dataChannel.Close()
// TODO: write for the spawned reader to return
s.onDone()
}()
}
s.maybeDeclareStreamDone()

select {
case s.writeAvailable <- struct{}{}:
Expand Down Expand Up @@ -186,6 +170,7 @@ func (s *stream) processIncomingFlag(flag *pb.Message_Flag) {
if s.receiveState == receiveStateReceiving {
s.receiveState = receiveStateDataRead
}
log.Errorln("received FIN", s.id)
case pb.Message_STOP_SENDING:
if s.sendState == sendStateSending {
s.sendState = sendStateReset
Expand All @@ -211,6 +196,7 @@ func (s *stream) maybeDeclareStreamDone() {
// See https://github.com/libp2p/specs/issues/575 for details.
// _ = s.dataChannel.Close()
// TODO: write for the spawned reader to return
s.dataChannel.Close()
s.onDone()
}
}
Expand Down
5 changes: 0 additions & 5 deletions test-plans/ping-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"id": "go-libp2p-head",
"containerImageID": "go-libp2p-head",
"transports": [
"tcp",
"ws",
"wss",
"quic-v1",
"webtransport",
"webrtc-direct"
],
"secureChannels": [
Expand Down
Loading