Skip to content

Commit

Permalink
Avoid segfault on shutdown
Browse files Browse the repository at this point in the history
```
srv6-ctrl  | [GIN] 2024/10/22 - 16:28:26 | 204 |       3.972µs | fd00::2:8000:0:3 | DELETE   "/routers/a0d59214-7805-4577-b59f-d5bb6bbbb8b2"
srv6-ctrl  | [GIN] 2024/10/22 - 16:28:27 | 204 |       4.756µs | fd00::2:8000:0:4 | DELETE   "/routers/f25ea57d-1d08-4063-a744-0fddd00bc358"
srv6-ctrl  | [GIN] 2024/10/22 - 16:28:27 | 204 |       3.153µs | fd00::2:8000:0:5 | DELETE   "/routers/26c55959-34ef-498c-b060-c932e053fadf"
srv6-ctrl  | [GIN] 2024/10/22 - 16:28:27 | 204 |        3.24µs | fd00::2:8000:0:2 | DELETE   "/routers/33174bca-0892-46f2-8052-418df245a5d2"
srv6-ctrl  | panic: runtime error: invalid memory address or nil pointer dereference
srv6-ctrl  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x99713e]
srv6-ctrl  |
srv6-ctrl  | goroutine 1 [running]:
srv6-ctrl  | github.com/nextmn/go-pfcp-networking/pfcp.(*onceClosePfcpConn).Close(...)
srv6-ctrl  |    /go/pkg/mod/github.com/nextmn/[email protected]/pfcp/entity.go:49
srv6-ctrl  | github.com/nextmn/go-pfcp-networking/pfcp.(*PFCPEntity).closePfcpConn(0xc0002d0e60)
srv6-ctrl  |    /go/pkg/mod/github.com/nextmn/[email protected]/pfcp/entity.go:75 +0xde
srv6-ctrl  | github.com/nextmn/go-pfcp-networking/pfcp.(*PFCPEntity).Close(0xc0002d0e60)
srv6-ctrl  |    /go/pkg/mod/github.com/nextmn/[email protected]/pfcp/entity.go:272 +0x29
srv6-ctrl  | github.com/nextmn/srv6-ctrl/internal/app.Setup.Run({0xc0002d85b0?, 0xc0002d0e60?}, {0xc19038, 0xc0001a7980})
srv6-ctrl  |    /go/pkg/mod/github.com/nextmn/[email protected]/internal/app/setup.go:36 +0x92
srv6-ctrl  | main.main.func2(0xc0001a7a00)
srv6-ctrl  |    /go/pkg/mod/github.com/nextmn/[email protected]/main.go:64 +0x1df
srv6-ctrl  | github.com/urfave/cli/v2.(*Command).Run(0xc0002da2c0, 0xc0001a7a00, {0xc0001a6000, 0x4, 0x4})
srv6-ctrl  |    /go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:276 +0x97d
srv6-ctrl  | github.com/urfave/cli/v2.(*App).RunContext(0xc0002d6000, {0xc19038, 0xc0001a7980}, {0xc0001a6000, 0x4, 0x4})
srv6-ctrl  |    /go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:333 +0x5a5
srv6-ctrl  | main.main()
srv6-ctrl  |    /go/pkg/mod/github.com/nextmn/[email protected]/main.go:89 +0x405
srv6-ctrl exited with code 2
```
  • Loading branch information
louisroyer committed Oct 22, 2024
1 parent 56a3459 commit 2bc53f0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pfcp/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func (e *PFCPEntity) closePfcpConn() error {
return nil
}
for _, v := range e.pfcpConns {
if v == nil {
continue
}
if err := v.Close(); err != nil {
return err
}
Expand Down Expand Up @@ -229,7 +232,7 @@ func (e *PFCPEntity) Serve(ctx context.Context, conn *PFCPConn) error {
e.registerPfcpConn(newconn)
serveCtx, cancel := context.WithCancel(ctx)
e.closeFunc = cancel
defer newconn.Close()
defer e.closePfcpConn()
e.recoveryTimeStamp = ie.NewRecoveryTimeStamp(time.Now())
for {
select {
Expand Down Expand Up @@ -268,8 +271,9 @@ func (e *PFCPEntity) Serve(ctx context.Context, conn *PFCPConn) error {

// Close stop the server and closes active PFCP connection.
func (e *PFCPEntity) Close() error {
e.closeFunc()
e.closePfcpConn()
if e.closeFunc != nil {
e.closeFunc()
}
return nil
}

Expand Down

0 comments on commit 2bc53f0

Please sign in to comment.