Skip to content

Commit

Permalink
fix: Update TCP connection timeout to 30 seconds (#94)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

Old TCP stream were not being closed correctly. This was because the
timeout was set to 24 hours which lead to the number of running go
routine as we start multiple per open connection.

This PR updates the timeout so connections are flushed more frequently.

- Closes #85 

## Short description of the changes
- Remove the close timeout config option
- Sets connection timeout to 30 seconds
- Updates the assembler to use `FlushCloseOlderThan`

## How to verify that this has the expected result
Connections are now flushed and closed correctly which helps keep open
go routines in check.
  • Loading branch information
MikeGoldsmith committed Aug 21, 2023
1 parent b7a36bd commit 4e80c79
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions assemblers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/rs/zerolog/log"
)

const closeTimeout time.Duration = time.Hour * 24
const timeout time.Duration = time.Minute * 5
const timeout time.Duration = time.Second * 30

var maxcount = flag.Int("c", -1, "Only grab this many packets, then exit")
var statsevery = flag.Int("stats", 1000, "Output statistics every N packets")
Expand Down Expand Up @@ -69,7 +68,6 @@ func NewConfig() *config {
Snaplen: *snaplen,
TsType: *tstype,
Promiscuous: *promisc,
CloseTimeout: closeTimeout,
Timeout: timeout,
}

Expand Down
2 changes: 1 addition & 1 deletion assemblers/tcp_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (h *tcpAssembler) Start() {
}
if count%h.config.Statsevery == 0 {
ref := packet.Metadata().CaptureInfo.Timestamp
flushed, closed := h.assembler.FlushWithOptions(reassembly.FlushOptions{T: ref.Add(-h.config.Timeout), TC: ref.Add(-h.config.CloseTimeout)})
flushed, closed := h.assembler.FlushCloseOlderThan(time.Now().Add(-h.config.Timeout))
log.Debug().
Int("flushed", flushed).
Int("closed", closed).
Expand Down

0 comments on commit 4e80c79

Please sign in to comment.