From 407c9e4588e35ad1e9d758c6478c8837d89207c4 Mon Sep 17 00:00:00 2001 From: lesismal Date: Thu, 22 Feb 2024 21:59:14 +0800 Subject: [PATCH 1/4] nbio.Conn: fix closeWithErrorWithoutLock panic --- conn_unix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conn_unix.go b/conn_unix.go index 1f0064df..f50f0007 100644 --- a/conn_unix.go +++ b/conn_unix.go @@ -772,7 +772,7 @@ func (c *Conn) closeWithErrorWithoutLock(err error) error { c.writeList = nil } - if c.p.g != nil { + if c.p != nil { c.p.deleteConn(c) } From 6d052f1f9f4732fdbd801c230cae07fac596998f Mon Sep 17 00:00:00 2001 From: lesismal Date: Thu, 22 Feb 2024 22:18:09 +0800 Subject: [PATCH 2/4] kqueue: revert to v1.3.21 --- poller_kqueue.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/poller_kqueue.go b/poller_kqueue.go index d8ac0a92..a067e8d5 100644 --- a/poller_kqueue.go +++ b/poller_kqueue.go @@ -104,23 +104,22 @@ func (p *poller) trigger() { func (p *poller) addRead(fd int) { p.mux.Lock() p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_READ}) - p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE}) p.mux.Unlock() p.trigger() } func (p *poller) resetRead(fd int) { - // p.mux.Lock() - // p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_DELETE, Filter: syscall.EVFILT_WRITE}) - // p.mux.Unlock() - // p.trigger() + p.mux.Lock() + p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_DELETE, Filter: syscall.EVFILT_WRITE}) + p.mux.Unlock() + p.trigger() } func (p *poller) modWrite(fd int) { - // p.mux.Lock() - // p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE}) - // p.mux.Unlock() - // p.trigger() + p.mux.Lock() + p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE}) + p.mux.Unlock() + p.trigger() } func (p *poller) deleteEvent(fd int) { From 422b237f138c3ce01e5fd8003e4b466dcdea0dbc Mon Sep 17 00:00:00 2001 From: lesismal Date: Fri, 23 Feb 2024 01:17:51 +0800 Subject: [PATCH 3/4] http: fix listener decrease online --- nbhttp/engine.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nbhttp/engine.go b/nbhttp/engine.go index 09b85014..81e57611 100644 --- a/nbhttp/engine.go +++ b/nbhttp/engine.go @@ -580,17 +580,21 @@ func (engine *Engine) AddConnNonTLSNonBlocking(conn *Conn, tlsConfig *tls.Config nbc, err := nbio.NBConn(conn.Conn) if err != nil { conn.Close() + decrease() logging.Error("AddConnNonTLSNonBlocking failed: %v", err) return } conn.Conn = nbc if nbc.Session() != nil { nbc.Close() + decrease() + logging.Error("AddConnNonTLSNonBlocking failed, invalid session: %v", nbc.Session()) return } key, err := conn2Array(nbc) if err != nil { nbc.Close() + decrease() logging.Error("AddConnNonTLSNonBlocking failed: %v", err) return } @@ -599,6 +603,7 @@ func (engine *Engine) AddConnNonTLSNonBlocking(conn *Conn, tlsConfig *tls.Config if len(engine.conns) >= engine.MaxLoad { engine.mux.Unlock() nbc.Close() + decrease() logging.Error("AddConnNonTLSNonBlocking failed: overload, already has %v online", engine.MaxLoad) return } @@ -622,9 +627,9 @@ func (engine *Engine) AddConnNonTLSBlocking(conn *Conn, tlsConfig *tls.Config, d engine.mux.Lock() if len(engine.conns) >= engine.MaxLoad { engine.mux.Unlock() - logging.Error("AddConnNonTLSBlocking failed: overload, already has %v online", engine.MaxLoad) conn.Close() decrease() + logging.Error("AddConnNonTLSBlocking failed: overload, already has %v online", engine.MaxLoad) return } switch vt := conn.Conn.(type) { @@ -660,18 +665,21 @@ func (engine *Engine) AddConnTLSNonBlocking(conn *Conn, tlsConfig *tls.Config, d nbc, err := nbio.NBConn(conn.Conn) if err != nil { conn.Close() + decrease() logging.Error("AddConnTLSNonBlocking failed: %v", err) return } conn.Conn = nbc if nbc.Session() != nil { nbc.Close() + decrease() logging.Error("AddConnTLSNonBlocking failed: session should not be nil") return } key, err := conn2Array(nbc) if err != nil { nbc.Close() + decrease() logging.Error("AddConnTLSNonBlocking failed: %v", err) return } @@ -680,6 +688,7 @@ func (engine *Engine) AddConnTLSNonBlocking(conn *Conn, tlsConfig *tls.Config, d if len(engine.conns) >= engine.MaxLoad { engine.mux.Unlock() nbc.Close() + decrease() logging.Error("AddConnTLSNonBlocking failed: overload, already has %v online", engine.MaxLoad) return } From 0aa4c4ce62c39c380c60f00c6e2eb158d4beb7ef Mon Sep 17 00:00:00 2001 From: lesismal Date: Fri, 23 Feb 2024 18:13:40 +0800 Subject: [PATCH 4/4] kqueue: revert to v1.5.0 --- poller_kqueue.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/poller_kqueue.go b/poller_kqueue.go index a067e8d5..d8ac0a92 100644 --- a/poller_kqueue.go +++ b/poller_kqueue.go @@ -104,22 +104,23 @@ func (p *poller) trigger() { func (p *poller) addRead(fd int) { p.mux.Lock() p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_READ}) + p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE}) p.mux.Unlock() p.trigger() } func (p *poller) resetRead(fd int) { - p.mux.Lock() - p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_DELETE, Filter: syscall.EVFILT_WRITE}) - p.mux.Unlock() - p.trigger() + // p.mux.Lock() + // p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_DELETE, Filter: syscall.EVFILT_WRITE}) + // p.mux.Unlock() + // p.trigger() } func (p *poller) modWrite(fd int) { - p.mux.Lock() - p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE}) - p.mux.Unlock() - p.trigger() + // p.mux.Lock() + // p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE}) + // p.mux.Unlock() + // p.trigger() } func (p *poller) deleteEvent(fd int) {