Skip to content

Commit

Permalink
修改tls的CloseWrite到最后进行,以避免线程安全问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luyu6056 committed Oct 27, 2020
1 parent 00bb0de commit 89b857a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions eventloop_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ func (lp *eventloop) loopIn(c *conn) error {
func (lp *eventloop) loopCloseConn(c *conn, err error) error {
if atomic.CompareAndSwapInt32(&c.opened, connStateCloseReady, connStateCloseLazyout) {
c.loop.eventHandler.OnClosed(c, err)
if c.tlsconn != nil {
c.tlsconn.CloseWrite()
}

c.loop.connections[c.fd/lp.svr.subLoopGroup.len()] = nil
lp.lazyChan <- c //进行最后的输出
}
Expand Down
4 changes: 4 additions & 0 deletions server_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ func (o *out) write() {
}
func (c *conn) lazywrite() {
if c.opened != connStateCloseOk {
if c.opened == connStateCloseLazyout && c.tlsconn != nil { //关闭前通知tls关闭
c.tlsconn.CloseWrite()
}
for c.outboundBuffer.Len() > 0 {
n, err := unix.Write(c.fd, c.outboundBuffer.Bytes())
if n <= 0 || err != nil {
Expand All @@ -632,6 +635,7 @@ func (c *conn) lazywrite() {
if c.opened == connStateCloseLazyout { //彻底删除close的c

c.opened = connStateCloseOk

unix.Close(c.fd)
c.loop.poller.Delete(c.fd)
c.releaseTCP()
Expand Down

0 comments on commit 89b857a

Please sign in to comment.