Get rid of io.EOF errors in logs

Closes: https://todo.sr.ht/~emersion/soju/150
This commit is contained in:
Simon Ser 2021-10-29 16:03:04 +02:00
parent 0cd18a78db
commit aa407a46e6
3 changed files with 7 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"encoding/base64" "encoding/base64"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -434,7 +435,7 @@ func (dc *downstreamConn) unmarshalText(uc *upstreamConn, text string) string {
func (dc *downstreamConn) readMessages(ch chan<- event) error { func (dc *downstreamConn) readMessages(ch chan<- event) error {
for { for {
msg, err := dc.ReadMessage() msg, err := dc.ReadMessage()
if err == io.EOF { if errors.Is(err, io.EOF) {
break break
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to read IRC command: %v", err) return fmt.Errorf("failed to read IRC command: %v", err)
@ -1354,7 +1355,7 @@ func (dc *downstreamConn) runUntilRegistered() error {
for !dc.registered { for !dc.registered {
msg, err := dc.ReadMessage() msg, err := dc.ReadMessage()
if err != nil { if err != nil {
return fmt.Errorf("failed to read IRC command: %v", err) return fmt.Errorf("failed to read IRC command: %w", err)
} }
err = dc.handleMessage(msg) err = dc.handleMessage(msg)

View File

@ -177,7 +177,9 @@ func (s *Server) handle(ic ircConn) {
id := atomic.AddUint64(&lastDownstreamID, 1) id := atomic.AddUint64(&lastDownstreamID, 1)
dc := newDownstreamConn(s, ic, id) dc := newDownstreamConn(s, ic, id)
if err := dc.runUntilRegistered(); err != nil { if err := dc.runUntilRegistered(); err != nil {
if !errors.Is(err, io.EOF) {
dc.logger.Print(err) dc.logger.Print(err)
}
} else { } else {
dc.user.events <- eventDownstreamConnected{dc} dc.user.events <- eventDownstreamConnected{dc}
if err := dc.readMessages(dc.user.events); err != nil { if err := dc.readMessages(dc.user.events); err != nil {

View File

@ -1725,7 +1725,7 @@ func (uc *upstreamConn) runUntilRegistered() error {
func (uc *upstreamConn) readMessages(ch chan<- event) error { func (uc *upstreamConn) readMessages(ch chan<- event) error {
for { for {
msg, err := uc.ReadMessage() msg, err := uc.ReadMessage()
if err == io.EOF { if errors.Is(err, io.EOF) {
break break
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to read IRC command: %v", err) return fmt.Errorf("failed to read IRC command: %v", err)