Skip to content

Fix 8 bugs in proxy + exclude log files from git#40

Merged
esrrhs merged 2 commits into
masterfrom
copilot/check-for-bugs
Apr 10, 2026
Merged

Fix 8 bugs in proxy + exclude log files from git#40
esrrhs merged 2 commits into
masterfrom
copilot/check-for-bugs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Multiple bugs across main.go, proxy/common.go, proxy/client.go, proxy/inputer.go, and proxy/outputer.go, plus a committed log file.

Bug Fixes

  • OOB panic (main.go): Slice length equality check ran after indexing into fromaddr/toaddr/proxyproto — reordered to validate lengths first
  • Dead comparison (common.go): uint32 msglen <= 0 is always false — changed to == 0 in both recvFrom and sendTo
  • Data races (common.go, inputer.go, outputer.go):
    • pingflag/pongflag mixed plain pointer dereference with atomic.Add across goroutines — replaced all reads/writes with atomic.Load/atomic.Store
    • ProxyConn.pinged and ProxyConn.actived accessed unsynchronized from multiple goroutines — changed both fields to int32 and guarded all accesses with sync/atomic
  • CRC check after dispatch (common.go): In recvFrom, CRC validation ran after recvch.Write(f), so corrupt frames were already consumed before detection — moved check before the write
  • Silent connection leak (client.go): processLoginRsp returned without setting serverconn.needclose = true when iniService failed, leaving the connection open
  • Typo (client.go): Thread group name "Clent""Client"

Git Hygiene

  • Added *.log to .gitignore
  • Removed previously committed proxy/default_DEBUG_2026-04-10.log from the index via git rm --cached

Copilot AI and others added 2 commits April 10, 2026 10:11
@esrrhs esrrhs marked this pull request as ready for review April 10, 2026 10:22
Copilot AI review requested due to automatic review settings April 10, 2026 10:22
Copy link
Copy Markdown

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 addresses multiple runtime correctness issues in the proxy implementation (primarily concurrency safety and argument validation) and improves repo hygiene by ignoring log files.

Changes:

  • Make ProxyConn.actived / pinged and ping/pong flags atomic to reduce data races; adjust message length checks and reorder CRC-check vs dispatch in recvFrom.
  • Fix a client connection lifecycle issue (needclose on iniService failure) and correct a client thread-group name typo.
  • Prevent CLI out-of-bounds panics by validating flag slice lengths before indexing; ignore *.log in git.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
proxy/common.go Switches activity/heartbeat counters and ping/pong flags to atomic operations; adjusts frame length checks and recv ordering.
proxy/inputer.go Uses atomic increment for sonny.actived to avoid races across goroutines.
proxy/outputer.go Uses atomic increment for sonny.actived to avoid races across goroutines.
proxy/client.go Fixes thread group name typo and ensures failed service init triggers connection close.
main.go Validates slice lengths before indexing into CLI flag arrays to avoid panics.
.gitignore Adds *.log to prevent committed log artifacts.
Comments suppressed due to low confidence (1)

proxy/common.go:281

  • pongtime is written in processPing and read here to populate a PONG frame, but it’s accessed via plain pointer dereference. Since sendTo runs concurrently with processPing, this is still a data race even after making pongflag atomic. Use atomic.StoreInt64 in processPing and atomic.LoadInt64 here (and keep pongtime 64-bit aligned) to make the handoff race-free.
			f = &ProxyFrame{}
			f.Type = FRAME_TYPE_PONG
			f.PongFrame = &PongFrame{}
			f.PongFrame.Time = *pongtime
		} else {

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

Comment thread proxy/common.go
Comment on lines +269 to +276
if atomic.LoadInt32(pingflag) > 0 {
atomic.StoreInt32(pingflag, 0)
f = &ProxyFrame{}
f.Type = FRAME_TYPE_PING
f.PingFrame = &PingFrame{}
f.PingFrame.Time = time.Now().UnixNano()
} else if *pongflag > 0 {
*pongflag = 0
} else if atomic.LoadInt32(pongflag) > 0 {
atomic.StoreInt32(pongflag, 0)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

pingflag / pongflag clearing uses atomic.LoadInt32(...) > 0 followed by atomic.StoreInt32(..., 0). If another goroutine increments the flag between the load and store, that increment can be lost, causing missed PING/PONG sends. Consider using atomic.SwapInt32(flag, 0) (or a CAS loop) so you clear the flag and observe the previous value atomically.

Copilot uses AI. Check for mistakes.
Comment thread proxy/common.go
Comment on lines 63 to 72
type ProxyConn struct {
conn network.Conn
established bool
sendch *common.Channel // *ProxyFrame
recvch *common.Channel // *ProxyFrame
actived int
pinged int
actived int32
pinged int32
id string
needclose bool
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

ProxyConn.actived / pinged were made atomic, but established and needclose are still plain bool fields that are written and read by multiple goroutines (e.g., login/open handlers vs checkPingActive/checkNeedClose). This remains a data race in Go. Consider converting them to int32 guarded by sync/atomic, or protecting the whole connection state with a mutex.

Copilot uses AI. Check for mistakes.
@esrrhs esrrhs merged commit 2858c23 into master Apr 10, 2026
6 checks passed
@esrrhs esrrhs deleted the copilot/check-for-bugs branch April 10, 2026 11:27
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.

3 participants