Skip to content

Commit

Permalink
log idle connection closing
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Jul 27, 2023
1 parent b9c1f75 commit 1e0c40a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (

var (
// ErrServerClosed is returned when server context is ended (by shutdown)
ErrServerClosed = errors.New("modbus server closed")
ErrServerClosed = errors.New("modbus server closed")
ErrServerIdleTimeout = errors.New("modbus server closed idle connection")

Check failure on line 26 in server/server.go

View workflow job for this annotation

GitHub Actions / test (1.19, ubuntu-latest)

exported var ErrServerIdleTimeout should have comment or be unexported

Check failure on line 26 in server/server.go

View workflow job for this annotation

GitHub Actions / test (1.20, ubuntu-latest)

exported var ErrServerIdleTimeout should have comment or be unexported
)

// PacketAssembler is called when server reads data from client connection. Is responsible for assembling data read
Expand Down Expand Up @@ -253,6 +254,7 @@ func (c *connection) handle(ctx context.Context) {
if n > 0 {
lastReceived = time.Now()
} else if time.Now().Sub(lastReceived) > idleTimeout {
c.onErrorFunc(ErrServerIdleTimeout)
return // close idle connection
} else {
continue // nothing read and not idle yet
Expand Down

0 comments on commit 1e0c40a

Please sign in to comment.