Skip to content

Commit

Permalink
Cleanup when unexpected packet received
Browse files Browse the repository at this point in the history
  • Loading branch information
waldner committed Oct 22, 2024
1 parent e69c06d commit fc0d8d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module github.com/pin/tftp/v3
module github.com/waldner/tftp/v3

go 1.17

require (
golang.org/x/net v0.15.0
golang.org/x/sys v0.13.0 // indirect
)
require golang.org/x/net v0.15.0

require golang.org/x/sys v0.13.0 // indirect
9 changes: 6 additions & 3 deletions receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"time"

"github.com/pin/tftp/v3/netascii"
"github.com/waldner/tftp/v3/netascii"
)

// IncomingTransfer provides methods that expose information associated with
Expand Down Expand Up @@ -258,6 +258,11 @@ func (r *receiver) abort(err error) error {
if r.conn == nil {
return nil
}
defer func() {
r.conn.close()
r.conn = nil
}()

if r.hook != nil {
r.hook.OnFailure(r.buildTransferStats(), err)
}
Expand All @@ -266,7 +271,5 @@ func (r *receiver) abort(err error) error {
if err != nil {
return err
}
r.conn.close()
r.conn = nil
return nil
}
9 changes: 6 additions & 3 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"time"

"github.com/pin/tftp/v3/netascii"
"github.com/waldner/tftp/v3/netascii"
)

// OutgoingTransfer provides methods to set the outgoing transfer size and
Expand Down Expand Up @@ -278,6 +278,11 @@ func (s *sender) abort(err error) error {
if s.conn == nil {
return nil
}
defer func() {
s.conn.close()
s.conn = nil
}()

if s.hook != nil {
s.hook.OnFailure(s.buildTransferStats(), err)
}
Expand All @@ -286,7 +291,5 @@ func (s *sender) abort(err error) error {
if err != nil {
return err
}
s.conn.close()
s.conn = nil
return nil
}
11 changes: 7 additions & 4 deletions single_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ func (s *Server) singlePortProcessRequests() error {
s.Unlock()
go func() {
err := s.handlePacket(localAddr, srcAddr, buf, cnt, maxSz, lc)
if err != nil && s.hook != nil {
s.hook.OnFailure(TransferStats{
SenderAnticipateEnabled: s.sendAEnable,
}, err)
if err != nil {
if s.hook != nil {
s.hook.OnFailure(TransferStats{
SenderAnticipateEnabled: s.sendAEnable,
}, err)
}
delete(s.handlers, srcAddr.String())
}
}()
}
Expand Down

0 comments on commit fc0d8d1

Please sign in to comment.