BYOK Personal Data Server (PDS) written in Go
ipfs vow atproto pds go
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: websocket read loop and add error helpers

+31 -6
+31 -6
server/handle_sync_subscribe_repos.go
··· 55 55 56 56 // drop the connection whenever a subscriber disconnects from the socket, we should get errors 57 57 go func() { 58 + defer cancel() 59 + 58 60 for { 59 - select { 60 - case <-ctx.Done(): 61 + if err := conn.SetReadDeadline(time.Now().Add(30 * time.Second)); err != nil { 62 + logger.Warn("error setting read deadline", "err", err) 61 63 return 62 - default: 63 - if _, _, err := conn.ReadMessage(); err != nil { 64 + } 65 + 66 + _, _, err := conn.ReadMessage() 67 + if err != nil { 68 + if isNormalClose(err) || isTimeout(err) { 69 + logger.Info("websocket disconnected", "err", err) 70 + } else { 64 71 logger.Warn("websocket error", "err", err) 65 - cancel() 66 - return 67 72 } 73 + return 68 74 } 69 75 } 70 76 }() ··· 136 142 } 137 143 }() 138 144 } 145 + 146 + func isNormalClose(err error) bool { 147 + if err == nil { 148 + return false 149 + } 150 + // Check if it's a normal close (status codes 1000-1005, etc.) 151 + // The error message typically contains "close 1000" or similar 152 + errStr := err.Error() 153 + return len(errStr) > 8 && errStr[:7] == "websocket: close" 154 + } 155 + 156 + func isTimeout(err error) bool { 157 + if err == nil { 158 + return false 159 + } 160 + // Check if it's a timeout error 161 + // Using string check as the library doesn't expose error types 162 + return err.Error() == "i/o timeout" 163 + }