Skip to content

fix(style): code style and process overhead - #28

Merged
Saxy merged 6 commits into
mainfrom
fix/code-style
Aug 4, 2026
Merged

fix(style): code style and process overhead#28
Saxy merged 6 commits into
mainfrom
fix/code-style

Conversation

@Saxy

@Saxy Saxy commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Description

Component:
Network / General

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance optimization (no change in behavior, improved speed/memory)
  • Refactoring (no functional changes, code cleanup)
  • Build / CI / Documentation

Related Issue

none


Technical Deep Dive & Context

  • fixed code style
  • removed duplicated code
  • reduced process overhead on resp for bycrpt operations

Performance & Benchmarks (If Applicable)

none


How Has This Been Tested?

  • go test
  • memtier_benchmark on the current version

Checklist

  • My code follows the existing code style of this project
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally (go test ./... and go test -race ./...)
  • I have updated the documentation (README, comments, or any relevant docs)
  • My changes generate no new go vet warnings
  • Any breaking changes are documented and communicated

Summary by CodeRabbit

  • New Features

    • Improved authentication handling for pipelined commands, ensuring commands wait for authentication to complete.
    • Added stronger protection against repeated failed authentication attempts.
    • Improved responsiveness during authentication under concurrent connection loads.
  • Bug Fixes

    • Fixed authentication failures so subsequent unauthorized commands are correctly rejected.
    • Improved handling of unknown authentication accounts with immediate failure reporting.
    • Preserved validation and error handling for ACL, role, and key-based operations.
    • Improved consistency when processing plaintext and TLS connections.

Saxy added 4 commits August 3, 2026 21:21
Signed-off-by: Maximilian Hagen <git@saxy.dev>
Signed-off-by: Maximilian Hagen <git@saxy.dev>
Signed-off-by: Maximilian Hagen <git@saxy.dev>
…rocessing bycrpt

Signed-off-by: Maximilian Hagen <git@saxy.dev>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f76c2035-9989-412c-a689-63dc6d7a4b23

📥 Commits

Reviewing files that changed from the base of the PR and between 01dd729 and 13b4dec.

📒 Files selected for processing (1)
  • internal/network/acl.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/network/acl.go

📝 Walkthrough

Walkthrough

The PR consolidates binary network codec and client operations through shared helpers. It also adds bounded asynchronous RESP authentication with pipeline gating, failure limits, worker lifecycle management, and integration coverage.

Changes

Network protocol helpers

Layer / File(s) Summary
Shared ACL and ROLE codecs
internal/network/role.go, internal/network/acl.go
Shared helpers encode and decode length-prefixed string and byte lists. ACL and ROLE list processing retains validation, truncation handling, and namespace copying.
Shared client operations
internal/network/client.go, internal/network/client_role.go, internal/network/client_acl.go
Keyed operations and typed ROLE list requests share request construction, transport, response validation, and payload retrieval.
Shared binary frame processing
internal/network/server.go
TLS and plaintext frame paths share authorization, handler execution, response writing, metrics, and frame-discard logic. Unknown RBAC users now fail immediately.

Asynchronous RESP authentication

Layer / File(s) Summary
Authentication worker lifecycle
internal/resp/server.go
The server adds authentication jobs, worker queues, connection state, conditional worker startup, and graceful worker shutdown.
Authentication dispatch and pipeline gating
internal/resp/server.go
AUTH verification uses bounded bcrypt workers. TLS and plaintext processing pause while verification is pending, then resume through connection wakeups. Failed attempts and queue saturation return authentication errors.
Authentication pipeline validation
internal/resp/server_test.go, internal/resp/benchmark_test.go
Tests cover pipelined successful and failed AUTH flows. Benchmarks use the revised dispatch return signature.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RESPClient
  participant RESPServer
  participant authJobQueue
  participant bcryptWorker
  participant gnetConnection
  RESPClient->>RESPServer: Send AUTH and pipelined command
  RESPServer->>authJobQueue: Queue copied credentials
  RESPServer-->>RESPClient: Pause pipelined command processing
  authJobQueue->>bcryptWorker: Verify copied credentials
  bcryptWorker->>gnetConnection: Wake with authentication result
  gnetConnection->>RESPServer: Resume processing
  RESPServer-->>RESPClient: Send AUTH and command responses
Loading

Possibly related PRs

  • Saxy/Tellstone#18: Refactors binary protocol AUTH handling and worker lifecycle behavior.
  • Saxy/Tellstone#23: Introduces related RBAC authentication and shared role codec behavior.
  • Saxy/Tellstone#27: Refactors ACL codecs, client handling, and authentication server logic.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately identifies the style cleanup and reduced processing overhead, which are central changes in the pull request.
Description check ✅ Passed The description includes all required sections and summarizes the refactoring, bcrypt changes, testing, and checklist status, despite limited test details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/code-style

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Saxy Saxy changed the title Fix/code style fix(style): code style and process overhead Aug 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/resp/server.go (1)

193-211: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Do not close authJobs while event-loop goroutines may still send to it.

ListenAndServe blocks in gnet.Run, and OnBoot only closes s.ready after s.eng is assigned. In the ctx.Done() shutdown path, close s.authJobs only after OnBoot has run successfully and s.eng.Stop(ctx) is guaranteed not to return early. Use a single stop marker or sync.Once checked in dispatchAuth/OnBoot, then close the channel only after shutdown is complete. Also make Shutdown(ctx) bounded by ctx instead of blocking indefinitely on s.workerWg.Wait().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/resp/server.go` around lines 193 - 211, The Shutdown method can
close authJobs while event-loop goroutines still send to it and can block
indefinitely waiting for workers. Coordinate shutdown through a single stop
marker or sync.Once shared by Shutdown, dispatchAuth, and OnBoot; only close
authJobs after OnBoot has completed successfully and eng.Stop(ctx) has fully
completed. Update worker waiting in Shutdown to honor ctx cancellation rather
than unconditionally blocking on workerWg.Wait().
🧹 Nitpick comments (1)
internal/network/role.go (1)

231-237: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract encodeU16String to match the existing decodeU16String helper.
The decode side already has a shared single-string helper (decodeU16String), but the encode side still repeats the "check length, append length, append bytes" pattern inline in three places across two files. Extracting a symmetric encodeU16String(buf []byte, s string) ([]byte, bool) removes the remaining duplication that encodeStringList/encodeByteList did not cover.

  • internal/network/role.go#L231-L237: replace the inline Name length-check-and-append block (lines 226-230) with encodeU16String.
  • internal/network/acl.go#L58-L64: replace the inline Username and Role length-check-and-append blocks (lines 43-52) with encodeU16String.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/network/role.go` around lines 231 - 237, The string encoding logic
is duplicated instead of using a shared helper. Add encodeU16String(buf []byte,
s string) ([]byte, bool) alongside the existing decodeU16String, then replace
the inline Name block in internal/network/role.go lines 226-230 and the Username
and Role blocks in internal/network/acl.go lines 43-52; the consolidated sites
internal/network/role.go lines 231-237 and internal/network/acl.go lines 58-64
require these call-site updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/resp/server.go`:
- Around line 193-211: The Shutdown method can close authJobs while event-loop
goroutines still send to it and can block indefinitely waiting for workers.
Coordinate shutdown through a single stop marker or sync.Once shared by
Shutdown, dispatchAuth, and OnBoot; only close authJobs after OnBoot has
completed successfully and eng.Stop(ctx) has fully completed. Update worker
waiting in Shutdown to honor ctx cancellation rather than unconditionally
blocking on workerWg.Wait().

---

Nitpick comments:
In `@internal/network/role.go`:
- Around line 231-237: The string encoding logic is duplicated instead of using
a shared helper. Add encodeU16String(buf []byte, s string) ([]byte, bool)
alongside the existing decodeU16String, then replace the inline Name block in
internal/network/role.go lines 226-230 and the Username and Role blocks in
internal/network/acl.go lines 43-52; the consolidated sites
internal/network/role.go lines 231-237 and internal/network/acl.go lines 58-64
require these call-site updates.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a87def9-5eb4-4533-a47b-8dcd6b230a81

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8265d and 8dad524.

📒 Files selected for processing (9)
  • internal/network/acl.go
  • internal/network/client.go
  • internal/network/client_acl.go
  • internal/network/client_role.go
  • internal/network/role.go
  • internal/network/server.go
  • internal/resp/benchmark_test.go
  • internal/resp/server.go
  • internal/resp/server_test.go

Saxy added 2 commits August 4, 2026 08:36
Signed-off-by: Maximilian Hagen <git@saxy.dev>
…eString and encodeByte

Signed-off-by: Maximilian Hagen <git@saxy.dev>
@Saxy
Saxy merged commit 8bc2536 into main Aug 4, 2026
5 checks passed
@Saxy
Saxy deleted the fix/code-style branch August 4, 2026 07:12
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