Resolve IRC client hostnames off the accept loop (closes #156)
check / check (push) Waiting to run
check / check (push) Waiting to run
acceptLoop called newConn, which did the reverse DNS lookup, with its three-second timeout, before the loop could accept the next connection, so one client whose address had no answering reverse DNS held up every other IRC connect. serve now does the lookup at its start, on the connection's own goroutine, and the accept loop only accepts. The server keeps the lookup function in a field, as it does the ping times, so that a test can give it one that blocks. The new test checks that a second client registers while the first one's lookup has not returned. Model: opus-5-5
This commit was merged in pull request #172.
This commit is contained in:
@@ -15,7 +15,8 @@ import (
|
||||
|
||||
// NewTestServer creates a Server suitable for testing, whose
|
||||
// connections use interval and deadline in place of
|
||||
// pingInterval and pongDeadline.
|
||||
// pingInterval and pongDeadline, and resolve in place of
|
||||
// resolveHost.
|
||||
// The caller must call Stop() when finished.
|
||||
func NewTestServer(
|
||||
log *slog.Logger,
|
||||
@@ -23,6 +24,7 @@ func NewTestServer(
|
||||
database *db.Database,
|
||||
brk *broker.Broker,
|
||||
interval, deadline time.Duration,
|
||||
resolve func(ctx context.Context, addr string) string,
|
||||
) *Server {
|
||||
globs := &globals.Globals{
|
||||
Appname: "neoirc",
|
||||
@@ -44,9 +46,16 @@ func NewTestServer(
|
||||
|
||||
pingInterval: interval,
|
||||
pongDeadline: deadline,
|
||||
resolveHost: resolve,
|
||||
}
|
||||
}
|
||||
|
||||
// ResolveHost is the reverse DNS lookup that a server made by
|
||||
// New does for each client.
|
||||
func ResolveHost(ctx context.Context, addr string) string {
|
||||
return resolveHost(ctx, addr)
|
||||
}
|
||||
|
||||
// Start exposes the unexported start method for tests.
|
||||
func (s *Server) Start(addr string) error {
|
||||
return s.start(context.Background(), addr)
|
||||
@@ -97,10 +106,7 @@ func NewTestConn(
|
||||
tcpConn net.Conn,
|
||||
nick string,
|
||||
) *Conn {
|
||||
conn := newConn(
|
||||
context.Background(), tcpConn, log,
|
||||
nil, nil, cfg, nil,
|
||||
)
|
||||
conn := newConn(tcpConn, log, nil, nil, cfg, nil)
|
||||
conn.nick = nick
|
||||
|
||||
return conn
|
||||
|
||||
Reference in New Issue
Block a user