From 28be3ba788f862d25005d5900a2415c6644be16f Mon Sep 17 00:00:00 2001 From: Sonu Kumar Saw <31889738+dev-saw99@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:49:58 +0530 Subject: [PATCH] chore(connections): lower log level from INFO to DEBUG for "already connected to this device" messages (fixes #9715) (#9722) ### Purpose The primary aim of this change is to minimize log clutter in production environments. There are many lines in the logs coming from an expected race condition when two devices connect `already connected to this device`. These messages do not indicate errors and can overwhelm the log files with unnecessary noise. By lowering the logging level, we enhance the usability of the logs, making it easier for users and developers to identify actual issues without being distracted ### Testing 1. Build syncthing locally 2. Start two Syncthing instances ```bash ./syncthing -no-browser -home=~/.config/syncthing1 ./syncthing -no-browser -home=~/.config/syncthing2 ``` 3. Enable the DEBUG logs from UI for `connections` package 4. Connect the synching instances by adding remote devices from the UI 5. Observe the logs for the message `XXXX already connected to this device` ### Screenshots ![image](https://github.com/user-attachments/assets/882ccb4c-d39d-463a-8f66-2aad97010700) ## Authorship Your name and email will be added automatically to the AUTHORS file based on the commit metadata. --- lib/connections/service.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/connections/service.go b/lib/connections/service.go index 5b69f2f99..0a09f6c7c 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -283,7 +283,11 @@ func (s *service) handleConns(ctx context.Context) error { } if err := s.connectionCheckEarly(remoteID, c); err != nil { - l.Infof("Connection from %s at %s (%s) rejected: %v", remoteID, c.RemoteAddr(), c.Type(), err) + if errors.Is(err, errDeviceAlreadyConnected) { + l.Debugf("Connection from %s at %s (%s) rejected: %v", remoteID, c.RemoteAddr(), c.Type(), err) + } else { + l.Infof("Connection from %s at %s (%s) rejected: %v", remoteID, c.RemoteAddr(), c.Type(), err) + } c.Close() continue }