Skip to content

Commit

Permalink
hotfix: add cancelRead to explicitly reset stream
Browse files Browse the repository at this point in the history
  • Loading branch information
chromato99 committed Oct 29, 2023
1 parent 6096c8b commit fb2d205
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/quic-s/quics-protocol

go 1.20
go 1.21

require (
github.com/google/uuid v1.4.0
Expand Down
10 changes: 1 addition & 9 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,25 @@ func (c *Connection) OpenTransaction(transactionName string, transactionFunc fun
newStream, err := qpStream.New(c.logLevel, stream)
if err != nil {
newStream.SendError(err.Error())
newStream.Close()
return err
}
defer newStream.Close()

transactionID, err := uuid.New().MarshalBinary()
if err != nil {
newStream.SendError(err.Error())
newStream.Close()
return err
}

err = TransactionHandshake(newStream, transactionName, transactionID)
if err != nil {
newStream.SendError(err.Error())
newStream.Close()
return err
}

err = transactionFunc(newStream, transactionName, transactionID)
if err != nil {
newStream.SendError(err.Error())
newStream.Close()
return err
}

err = newStream.Close()
if err != nil {
return err
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ func (h *Handler) RouteTransaction(conn *qpConn.Connection) error {
return err
}
go func() {
defer func() {
err = stream.Close()
if err != nil {
log.Println("quics-protocol: ", err)
}
}()

defer stream.Close()
transaction, err := qpConn.RecvTransactionHandshake(stream)
if err != nil {
log.Println("quics-protocol: ", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (s *Stream) Close() error {
if s == nil || s.Stream == nil {
return errors.New("stream is nil")
}
s.Stream.CancelRead(0)
err := s.Stream.Close()
if err != nil {
return err
Expand Down

0 comments on commit fb2d205

Please sign in to comment.