Skip to content

Commit

Permalink
vetu run: do not panic on context cancellation (#55)
Browse files Browse the repository at this point in the history
When context is canceled dhcp.server.Serve() might return io.EOF,
which causes the "vetu run" to panic. Ignore any errors that occured
after the context cancellation.
  • Loading branch information
edigaryev authored Aug 5, 2024
1 parent 0839522 commit 31d4d1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/network/software/dhcp/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func New(st *stack.Stack, gatewayIP net.IP, vmIP net.IP) (*DHCP, error) {
func (dhcp *DHCP) Run(ctx context.Context) error {
go func() {
<-ctx.Done()
dhcp.server.Close()
_ = dhcp.server.Close()
}()

return dhcp.server.Serve()
Expand Down
10 changes: 9 additions & 1 deletion internal/network/software/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@ func New(vmHardwareAddr net.HardwareAddr) (*Network, error) {

go func() {
if err := gvisor.Run(ctx); err != nil {
if errors.Is(ctx.Err(), context.Canceled) {
return
}

panic(err)
}
}()

go func() {
if err := dhcp.Run(context.Background()); err != nil {
if err := dhcp.Run(ctx); err != nil {
if errors.Is(ctx.Err(), context.Canceled) {
return
}

panic(err)
}
}()
Expand Down

0 comments on commit 31d4d1e

Please sign in to comment.