| 491 | } |
| 492 | |
| 493 | func (t *TCPTransport) writeWorker() { |
| 494 | defer t.writeWG.Done() |
| 495 | for req := range t.writeCh { |
| 496 | b, addr := req.b, req.addr |
| 497 | t.sentPackets.Inc() |
| 498 | t.sentPacketsBytes.Add(float64(len(b))) |
| 499 | err := t.writeTo(b, addr) |
| 500 | if err != nil { |
| 501 | t.sentPacketsErrors.Inc() |
| 502 | |
| 503 | logLevel := level.Warn(t.logger) |
| 504 | if strings.Contains(err.Error(), "connection refused") { |
| 505 | // The connection refused is a common error that could happen during normal operations when a node |
| 506 | // shutdown (or crash). It shouldn't be considered a warning condition on the sender side. |
| 507 | logLevel = t.debugLog() |
| 508 | } |
| 509 | logLevel.Log("msg", "WriteTo failed", "addr", addr, "err", err) |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | func (t *TCPTransport) writeTo(b []byte, addr string) error { |
| 515 | // Open connection, write packet header and data, data hash, close. Simple. |