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

Don't close connection if Listen* fails #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vincentbernat
Copy link

When ListenUDP/ListenPacket fail, the connection is nil and therefore,
we cannot call Close() on it.

Before:

 16:47 CEST ❱ ./goflow-v3.4.2-8-g0c2503d67cc8-linux-x86_64 -kafka=false -nf.port 9995 -nfl=false -sflow=false
INFO[0000] Starting GoFlow
INFO[0000] Listening on UDP :9995                        Type=NetFlow
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f644a]

goroutine 23 [running]:
github.com/cloudflare/goflow/v3/utils.UDPRoutine(0x90460d, 0x7, 0xc00021c3c0, 0x1, 0x0, 0x0, 0x270b, 0x0, 0x99b358, 0xc00021a930, ...)
        /home/bernat/code/free/goflow/utils/utils.go:291 +0x140a
github.com/cloudflare/goflow/v3/utils.(*StateNetFlow).FlowRoutine(0xc000224900, 0x1, 0x0, 0x0, 0x270b, 0x0, 0x2, 0x0)
        /home/bernat/code/free/goflow/utils/netflow.go:358 +0x15c
main.main.func2(0xc000224900, 0xc00021e260)
        /home/bernat/code/free/goflow/cmd/goflow/goflow.go:134 +0x226
created by main.main
        /home/bernat/code/free/goflow/cmd/goflow/goflow.go:129 +0x3da

After:

 16:48 CEST ❱ ./goflow-v3.4.2-8-g0c2503d67cc8-linux-x86_64 -kafka=false -nf.port 9995 -nfl=false -sflow=false
INFO[0000] Starting GoFlow
INFO[0000] Listening on UDP :9995                        Type=NetFlow
FATA[0000] Fatal error: could not listen to UDP (listen udp :9995: bind: address already in use)

When ListenUDP/ListenPacket fail, the connection is nil and therefore,
we cannot call `Close()` on it.

Before:

```
 16:47 CEST ❱ ./goflow-v3.4.2-8-g0c2503d67cc8-linux-x86_64 -kafka=false -nf.port 9995 -nfl=false -sflow=false
INFO[0000] Starting GoFlow
INFO[0000] Listening on UDP :9995                        Type=NetFlow
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f644a]

goroutine 23 [running]:
github.com/cloudflare/goflow/v3/utils.UDPRoutine(0x90460d, 0x7, 0xc00021c3c0, 0x1, 0x0, 0x0, 0x270b, 0x0, 0x99b358, 0xc00021a930, ...)
        /home/bernat/code/free/goflow/utils/utils.go:291 +0x140a
github.com/cloudflare/goflow/v3/utils.(*StateNetFlow).FlowRoutine(0xc000224900, 0x1, 0x0, 0x0, 0x270b, 0x0, 0x2, 0x0)
        /home/bernat/code/free/goflow/utils/netflow.go:358 +0x15c
main.main.func2(0xc000224900, 0xc00021e260)
        /home/bernat/code/free/goflow/cmd/goflow/goflow.go:134 +0x226
created by main.main
        /home/bernat/code/free/goflow/cmd/goflow/goflow.go:129 +0x3da
```

After:

```
 16:48 CEST ❱ ./goflow-v3.4.2-8-g0c2503d67cc8-linux-x86_64 -kafka=false -nf.port 9995 -nfl=false -sflow=false
INFO[0000] Starting GoFlow
INFO[0000] Listening on UDP :9995                        Type=NetFlow
FATA[0000] Fatal error: could not listen to UDP (listen udp :9995: bind: address already in use)
```
tgragnato pushed a commit to tgragnato/goflow that referenced this pull request Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant