mnet: fix error handling during listen, to prevent a panic when a socket is taken
This commit is contained in:
parent
398d887514
commit
b2aa2f73bd
16
mnet/mnet.go
16
mnet/mnet.go
@ -93,20 +93,20 @@ func InstListener(cmp *mcmp.Component, opts ...ListenerOpt) *Listener {
|
||||
),
|
||||
)
|
||||
|
||||
mrun.InitHook(cmp, func(context.Context) error {
|
||||
var err error
|
||||
|
||||
mrun.InitHook(cmp, func(ctx context.Context) error {
|
||||
cmp.Annotate("proto", lOpts.proto, "addr", *addr)
|
||||
|
||||
var err error
|
||||
if lOpts.isPacketConn() {
|
||||
l.PacketConn, err = net.ListenPacket(lOpts.proto, *addr)
|
||||
if l.PacketConn, err = net.ListenPacket(lOpts.proto, *addr); err != nil {
|
||||
return merr.Wrap(err, cmp.Context(), ctx)
|
||||
}
|
||||
cmp.Annotate("addr", l.PacketConn.LocalAddr().String())
|
||||
} else {
|
||||
l.Listener, err = net.Listen(lOpts.proto, *addr)
|
||||
cmp.Annotate("addr", l.Listener.Addr().String())
|
||||
if l.Listener, err = net.Listen(lOpts.proto, *addr); err != nil {
|
||||
return merr.Wrap(err, cmp.Context(), ctx)
|
||||
}
|
||||
if err != nil {
|
||||
return merr.Wrap(err, cmp.Context())
|
||||
cmp.Annotate("addr", l.Listener.Addr().String())
|
||||
}
|
||||
|
||||
mlog.From(cmp).Info("listening")
|
||||
|
Loading…
Reference in New Issue
Block a user