Skip to content

fix: Simplify session store and delete logic#3

Open
Unbreathable wants to merge 2 commits intomainfrom
fix/session-simplification
Open

fix: Simplify session store and delete logic#3
Unbreathable wants to merge 2 commits intomainfrom
fix/session-simplification

Conversation

@Unbreathable
Copy link
Contributor

This MR does the following things:

  • Simplifies session store and delete logic + gets rid of the global mutex
  • Makes sure sessions are properly copied and the cache is only accessed where absolutely needed (to prevent messing up with mutexes)

- Also make sure sessions are properly copied
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the session management system to remove the global mutex (SessionCache struct with its global mutex) and simplify the session store and delete logic. The changes aim to improve concurrency by relying on sync.Map's built-in synchronization and per-SessionsList mutexes rather than a single global lock.

Changes:

  • Removed the SessionCache wrapper struct with its global mutex, replacing it with direct use of sync.Map
  • Refactored createSession to use LoadOrStore pattern instead of multiple Load operations with global locking
  • Updated GetSessions to create defensive copies of session slices to prevent external modification
  • Simplified SendEventToUser and GetConnections to reuse GetSessions method

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
neogate.go Removes SessionCache struct and global mutex, replaces with direct sync.Map usage
sessions.go Refactors session creation/deletion logic and adds defensive copying in GetSessions
send.go Simplifies SendEventToUser by reusing GetSessions method, removes unnecessary error handling
connections.go Simplifies GetConnections by delegating to GetSessions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Unbreathable Unbreathable moved this to Backlog in Planning Mar 3, 2026
@Unbreathable Unbreathable moved this from Backlog to In progress in Planning Mar 3, 2026
@Unbreathable Unbreathable self-assigned this Mar 3, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Unbreathable Unbreathable assigned tiemingo and unassigned Unbreathable Mar 4, 2026
@Unbreathable Unbreathable moved this from In progress to In review in Planning Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants