Fix concurrency races, unchecked type assertions, and cross-platform syscall issues#49
Merged
Merged
Conversation
5 tasks
- Fix TOCTOU race condition in Respond() cache with double-checked locking - Fix TOCTOU race in WriteLevel() by holding lock through write operation - Fix unchecked type assertions in getFileMutex(), hashTime(), ToTime() - Fix Windows syscall locale-dependent error string comparison - Fix unchecked Close() calls in IsReadable, IsWritable, IsPortAvailable, CheckTCPConn - Add nil receiver safety to HashMap read methods Agent-Logs-Url: https://github.com/sivaosorg/replify/sessions/ac8fb3f3-62df-4cbf-9ddb-e277ddaa82fe Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
…nt Respond Agent-Logs-Url: https://github.com/sivaosorg/replify/sessions/ac8fb3f3-62df-4cbf-9ddb-e277ddaa82fe Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
…eedback Agent-Logs-Url: https://github.com/sivaosorg/replify/sessions/ac8fb3f3-62df-4cbf-9ddb-e277ddaa82fe Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Conduct comprehensive Go code review for replify
Fix concurrency races, unchecked type assertions, and cross-platform syscall issues
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Comprehensive audit addressing concurrency safety, panic prevention, cross-platform compatibility, and resource management across the codebase.
Concurrency safety
Respond()TOCTOU race — Hash was computed under read lock but consumed after lock promotion. Re-computes hash under write lock with proper double-checked locking:WriteLevel()TOCTOU race —lfw.muwas released beforerf.write(p), allowing concurrentClose()to invalidate therotatingFilebetween lookup and use. Now holds lock through the write.Panic prevention
hashTime(),ToTime(), andgetFileMutex()— all were usingv.(T)form which panics on type mismatch.HashMap.Get,Size,IsEmpty,ContainsKey,KeySet.Cross-platform compatibility
lock_windows.go— Replaced locale-dependenterr.Error() != "The operation completed successfully."witherr != syscall.Errno(0). The string comparison fails on non-English Windows.Resource management
deferforClose()calls inIsReadable,IsWritable,IsPortAvailable,CheckTCPConn— previously calledClose()inline, leaking on hypothetical future early-return paths.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
this.host.definitely.does.not.exist.invalid/tmp/go-build918891802/b262/sysx.test /tmp/go-build918891802/b262/sysx.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 -I cgo 0224729/b193/ x64/pkg/tool/lin--64 --gdwarf-5 --64 -o x64/pkg/tool/lin-trimpath 0224�� _.a -I ache/go/1.24.13/-lang=go1.24 --gdwarf-5 ions =0 ache/go/1.24.13//tmp/go-build918891802/b203/vet.cfg(dns block)/tmp/go-build676607140/b262/sysx.test /tmp/go-build676607140/b262/sysx.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 8918�� ache/go/1.24.13/x64/src/net cfg x64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o x64/pkg/tool/linux_amd64/vet -p 891802/b191/_pkg_.a -trimpath(dns block)/tmp/go-build723361286/b262/sysx.test /tmp/go-build723361286/b262/sysx.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 -o 891802/b214/_pkg_.a -trimpath sh -p crypto/internal/-o -lang=go1.24 as -I /opt/hostedtoolc-installsuffix 2 ux_amd64/compile-s --gdwarf-5 --64 -o ux_amd64/compile-buildtags(dns block)If you need me to access, download, or install something from one of these locations, you can either: