Skip to content

fix: downgrade 'websocket session ended' log level from Error to Warn in Client.Run reconnection loop - #176

Open
nudgebee-dev[bot] wants to merge 1 commit into
mainfrom
fix/fix-downgrade-websocket-session-ended-lo-1793159234
Open

nudgebee-dev[bot] wants to merge 1 commit into
mainfrom
fix/fix-downgrade-websocket-session-ended-lo-1793159234

Conversation

@nudgebee-dev

@nudgebee-dev nudgebee-dev Bot commented Oct 28, 2026

Copy link
Copy Markdown

Description

Inside the Client.Run reconnection loop in pkg/ws/client.go, when connectAndServe(ctx) terminates with an error (such as transient network disconnection, TCP reset, or relay restart), the error is currently logged at Error level using c.logger.Error("websocket session ended", "err", err). Because the client is designed to automatically reconnect with exponential backoff, transient disconnections are expected operational events. Logging them at Error level triggers false-positive high-severity error alerts and increments error log metrics unnecessarily.

This change downgrades the log level from Error to Warn (c.logger.Warn("websocket session ended", "err", err)), ensuring session termination events remain visible for diagnostics without triggering benign error-level alerts during normal reconnect cycles.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Enhancement (non-breaking change which improves existing functionality)
  • Refactor (non-breaking change which improves code structure)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation
  • CI/CD

Original Error/Logs

Click to expand the original error that triggered this fix
Downgrade 'websocket session ended' log level from Error to Warn or Info during reconnect loop in pkg/ws/client.go to prevent transient network drops from triggering high-severity error alerts.

Files located during the investigation: pkg/ws/client.go

The investigation already read this code:
**Code examined**

- `pkg/ws/client.go`:120-124 — Logging of websocket session ended at ERROR level inside the Client.Run reconnection loop

err := c.connectAndServe(ctx)
if err != nil {
c.logger.Error("websocket session ended", "err", err)
}


- `pkg/ws/client.go`:269-275 — Read loop error handling returning errors for non-normal WebSocket closures

_, msg, err := conn.ReadMessage()
if err != nil {
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
return nil
}
return fmt.Errorf("read error: %w", err)
}



If part of the requested change is already present in the code above, do not repeat it: implement the part that is missing. If the whole request is already satisfied, make no change and report that, citing the code that satisfies it.

How Has This Been Tested?

  • Unit tests
  • Manual testing

Checklist

  • CLA signed (the CLA bot will prompt on your first PR)
  • make validate passes (fmt + lint + test)
  • Docs updated if the wire shape, config surface, or proxy module behavior changed

🤖 This PR was automatically generated by NudgeBee AI coding agent

Powered by AI-driven code analysis and automated fix generation

🔍 View Original Investigation

Click the link above to see the full investigation and analysis that led to this fix

View Detailed Nubi Conversation


✅ Verification

Build verification passed for the affected modules.

Commands run
PASSED (cd . && go build ./...) exit=0
go: downloading github.com/spf13/viper v1.21.0
go: downloading github.com/fsnotify/fsnotify v1.9.0
go: downloading github.com/go-viper/mapstructure/v2 v2.4.0
go: downloading github.com/sagikazarmark/locafero v0.11.0
go: downloading github.com/spf13/afero v1.15.0
go: downloading github.com/spf13/cast v1.10.0
go: downloading github.com/spf13/pflag v1.0.10
go: downloading github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8
go: downloading github.com/subosito/gotenv v1.6.0
go: downloading github.com/pelletier/go-toml/v2 v2.2.4
go: downloading go.yaml.in/yaml/v3 v3.0.4

… in Client.Run reconnection loop

# Description

Inside the `Client.Run` reconnection loop in `pkg/ws/client.go`, when `connectAndServe(ctx)` terminates with an error (such as transient network disconnection, TCP reset, or relay restart), the error is currently logged at `Error` level using `c.logger.Error("websocket session ended", "err", err)`. Because the client is designed to automatically reconnect with exponential backoff, transient disconnections are expected operational events. Logging them at `Error` level triggers false-positive high-severity error alerts and increments error log metrics unnecessarily.

This change downgrades the log level from `Error` to `Warn` (`c.logger.Warn("websocket session ended", "err", err)`), ensuring session termination events remain visible for diagnostics without triggering benign error-level alerts during normal reconnect cycles.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Enhancement (non-breaking change which improves existing functionality)
- [ ] Refactor (non-breaking change which improves code structure)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation
- [ ] CI/CD

## Original Error/Logs

<details>
<summary>Click to expand the original error that triggered this fix</summary>

```
Downgrade 'websocket session ended' log level from Error to Warn or Info during reconnect loop in pkg/ws/client.go to prevent transient network drops from triggering high-severity error alerts.

Files located during the investigation: pkg/ws/client.go

The investigation already read this code:
**Code examined**

- `pkg/ws/client.go`:120-124 — Logging of websocket session ended at ERROR level inside the Client.Run reconnection loop

```
err := c.connectAndServe(ctx)
		if err != nil {
			c.logger.Error("websocket session ended", "err", err)
		}
```

- `pkg/ws/client.go`:269-275 — Read loop error handling returning errors for non-normal WebSocket closures

```
_, msg, err := conn.ReadMessage()
		if err != nil {
			if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
				return nil
			}
			return fmt.Errorf("read error: %w", err)
		}
```

If part of the requested change is already present in the code above, do not repeat it: implement the part that is missing. If the whole request is already satisfied, make no change and report that, citing the code that satisfies it.
```

</details>

# How Has This Been Tested?

- [x] Unit tests
- [ ] Manual testing

# Checklist

- [ ] CLA signed (the CLA bot will prompt on your first PR)
- [x] `make validate` passes (fmt + lint + test)
- [ ] Docs updated if the wire shape, config surface, or proxy module behavior changed

---

🤖 **This PR was automatically generated by [NudgeBee](https://nudgebee.com) AI coding agent**

*Powered by AI-driven code analysis and automated fix generation*

🔍 **[View Original Investigation](https://dev.nudgebee.pollux.in/investigate?id=c89fed88-1104-41a8-899c-052609bfafc9)**

*Click the link above to see the full investigation and analysis that led to this fix*

View Detailed **[Nubi Conversation](https://dev.nudgebee.pollux.in/ask-nudgebee?accountId=f13ddc45-07f3-42b4-bd0e-19606c852d18&session_id=event-4e4fee2c9ba759b6)**

---

### ✅ Verification

Build verification passed for the affected modules.

<details><summary>Commands run</summary>

```
PASSED (cd . && go build ./...) exit=0
go: downloading github.com/spf13/viper v1.21.0
go: downloading github.com/fsnotify/fsnotify v1.9.0
go: downloading github.com/go-viper/mapstructure/v2 v2.4.0
go: downloading github.com/sagikazarmark/locafero v0.11.0
go: downloading github.com/spf13/afero v1.15.0
go: downloading github.com/spf13/cast v1.10.0
go: downloading github.com/spf13/pflag v1.0.10
go: downloading github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8
go: downloading github.com/subosito/gotenv v1.6.0
go: downloading github.com/pelletier/go-toml/v2 v2.2.4
go: downloading go.yaml.in/yaml/v3 v3.0.4
```

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant