From cc34a90fb46348fd4588d4191ddba0a1d27c1132 Mon Sep 17 00:00:00 2001 From: Zhaozhong Ni Date: Thu, 12 Jul 2018 13:38:26 -0700 Subject: netstack: do not defer panicable logic in tcp main loop. PiperOrigin-RevId: 204355026 Change-Id: I1a8229879ea3b58aa861a4eb4456fd7aff99863d --- pkg/tcpip/transport/tcp/connect.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'pkg/tcpip') diff --git a/pkg/tcpip/transport/tcp/connect.go b/pkg/tcpip/transport/tcp/connect.go index 33bf4fc0b..8d70eb45a 100644 --- a/pkg/tcpip/transport/tcp/connect.go +++ b/pkg/tcpip/transport/tcp/connect.go @@ -828,7 +828,7 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error { var closeTimer *time.Timer var closeWaker sleep.Waker - defer func() { + epilogue := func() { // e.mu is expected to be hold upon entering this section. if e.snd != nil { @@ -849,7 +849,7 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error { // When the protocol loop exits we should wake up our waiters. e.waiterQueue.Notify(waiter.EventHUp | waiter.EventErr | waiter.EventIn | waiter.EventOut) - }() + } if handshake { // This is an active connection, so we must initiate the 3-way @@ -867,7 +867,8 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error { e.mu.Lock() e.state = stateError e.hardError = err - // Lock released in deferred statement. + // Lock released below. + epilogue() return err } @@ -1013,7 +1014,9 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error { if err := funcs[v].f(); err != nil { e.mu.Lock() e.resetConnectionLocked(err) - // Lock released in deferred statement. + // Lock released below. + epilogue() + return nil } } @@ -1021,7 +1024,8 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error { // Mark endpoint as closed. e.mu.Lock() e.state = stateClosed - // Lock released in deferred statement. + // Lock released below. + epilogue() return nil } -- cgit v1.2.3