fix: add status field to service list/detail APIs, unify observeStats retry pattern, fix router bugs

- api: add fillServiceStatus helper and call it from getServiceList/getService
  so status field appears in service list and detail API responses
- observeStats: unify retry pattern across all 9 handlers (http, http2, masque,
  relay, router, socks4, socks5, tungo, tunnel) — buffer events on failure,
  continue to skip fresh collection, clear on success; fix event-loss bug
  where interim events were dropped during retry cycles
- handler/router: check WriteTo/Write return errors in associate.go and
  entrypoint.go; fix DelConnector and ConnectorPool.Del using RLock instead
  of Lock (write under read lock); remove unused fields t and cancel
This commit is contained in:
ginuerzh
2026-06-03 22:12:08 +08:00
parent 785d52da31
commit 95874c53f5
14 changed files with 150 additions and 103 deletions
+15 -5
View File
@@ -52,7 +52,9 @@ func (h *routerHandler) handleAssociate(ctx context.Context, conn net.Conn, netw
if !rid.Equal(routerID) {
resp.Status = relay.StatusHostUnreachable
resp.WriteTo(conn)
if _, werr := resp.WriteTo(conn); werr != nil {
log.Error(werr)
}
err := fmt.Errorf("no route to host %s", host)
log.Error(err)
return err
@@ -62,7 +64,9 @@ func (h *routerHandler) handleAssociate(ctx context.Context, conn net.Conn, netw
uuid, err := uuid.NewRandom()
if err != nil {
resp.Status = relay.StatusInternalServerError
resp.WriteTo(conn)
if _, werr := resp.WriteTo(conn); werr != nil {
log.Error(werr)
}
return
}
connectorID := relay.NewConnectorID(uuid[:])
@@ -72,7 +76,9 @@ func (h *routerHandler) handleAssociate(ctx context.Context, conn net.Conn, netw
ID: connectorID,
},
)
resp.WriteTo(conn)
if _, werr := resp.WriteTo(conn); werr != nil {
log.Error(werr)
}
conn = &packetConn{conn}
@@ -203,7 +209,9 @@ func (h *routerHandler) handlePacket(ctx context.Context, data []byte, routerID
if c := h.pool.Get(routerID, route.Gateway); c != nil {
if w := c.Writer(); w != nil {
w.Write(data)
if _, werr := w.Write(data); werr != nil {
log.Error(werr)
}
}
return nil
}
@@ -231,7 +239,9 @@ func (h *routerHandler) handlePacket(ctx context.Context, data []byte, routerID
req.WriteTo(&buf)
buf.Write(data)
h.epConn.WriteTo(buf.Bytes(), raddr)
if _, werr := h.epConn.WriteTo(buf.Bytes(), raddr); werr != nil {
log.Error(werr)
}
return nil
}