fix: recover from panics in websocket handlers to prevent server crash#240
Conversation
a panic in any handler propagated up and killed the process; defer recover logs the method name and stack trace, then sends a clean error response
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Cache: Disabled due to data retention organization setting Knowledge base: Disabled due to data retention organization setting WalkthroughThis PR makes two independent changes. First, it reorganizes the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@go.mod`:
- Around line 6-53: The go.mod changes removed or altered // indirect markers
for many modules (the entries shown) though none are directly imported; restore
correct indirect/direct annotations by reverting the reorganization or running
"go mod tidy" to regenerate go.mod and go.sum, ensuring modules like
github.com/Masterminds/semver, github.com/sirupsen/logrus, golang.org/x/crypto,
etc. return to their proper indirect status; verify the go.mod matches the
output of "go mod tidy" and commit that result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 10e89f54-8627-4773-8ab1-b1d18a852786
📒 Files selected for processing (2)
go.modserver/websocket.go
| al.essio.dev/pkg/shellescape v1.5.1 | ||
| github.com/Masterminds/semver v1.5.0 | ||
| github.com/cenkalti/backoff v2.2.1+incompatible | ||
| github.com/danieljoos/wincred v1.2.2 | ||
| github.com/danielpaulus/go-ios v1.0.211 | ||
| github.com/davecgh/go-spew v1.1.1 | ||
| github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 | ||
| github.com/godbus/dbus/v5 v5.1.0 | ||
| github.com/google/btree v1.1.2 | ||
| github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 | ||
| github.com/google/uuid v1.6.0 | ||
| github.com/gorilla/websocket v1.5.3 | ||
| github.com/grandcat/zeroconf v1.0.0 | ||
| github.com/hashicorp/golang-lru/v2 v2.0.7 | ||
| github.com/inconshreveable/mousetrap v1.1.0 | ||
| github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 | ||
| github.com/miekg/dns v1.1.57 | ||
| github.com/onsi/ginkgo/v2 v2.9.5 | ||
| github.com/pierrec/lz4 v2.6.1+incompatible | ||
| github.com/pkg/errors v0.9.1 | ||
| github.com/pmezard/go-difflib v1.0.0 | ||
| github.com/quic-go/quic-go v0.40.1-0.20231203135336-87ef8ec48d55 | ||
| github.com/sevlyar/go-daemon v0.1.6 | ||
| github.com/sirupsen/logrus v1.9.3 | ||
| github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 | ||
| github.com/spf13/cobra v1.9.1 | ||
| github.com/spf13/pflag v1.0.6 | ||
| github.com/stretchr/testify v1.10.0 | ||
| github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9 | ||
| github.com/yapingcat/gomedia v0.0.0-20240906162731-17feea57090c | ||
| github.com/zalando/go-keyring v0.2.6 | ||
| go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 | ||
| go.uber.org/mock v0.5.0 | ||
| golang.org/x/crypto v0.45.0 | ||
| golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 | ||
| golang.org/x/mod v0.29.0 | ||
| golang.org/x/net v0.47.0 | ||
| golang.org/x/sync v0.18.0 | ||
| golang.org/x/sys v0.38.0 | ||
| golang.org/x/text v0.31.0 | ||
| golang.org/x/time v0.5.0 | ||
| golang.org/x/tools v0.38.0 | ||
| golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 | ||
| gopkg.in/ini.v1 v1.67.0 | ||
| gopkg.in/yaml.v3 v3.0.1 | ||
| gvisor.dev/gvisor v0.0.0-20240405191320-0878b34101b5 | ||
| howett.net/plist v1.0.1 | ||
| software.sslmate.com/src/go-pkcs12 v0.2.0 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check if packages marked as direct dependencies are actually imported
packages=(
"al.essio.dev/pkg/shellescape"
"github.com/Masterminds/semver"
"github.com/cenkalti/backoff"
"github.com/davecgh/go-spew"
"github.com/go-task/slim-sprig"
"github.com/godbus/dbus/v5"
"github.com/google/btree"
"github.com/google/pprof"
"github.com/grandcat/zeroconf"
"github.com/inconshreveable/mousetrap"
"github.com/kardianos/osext"
"github.com/miekg/dns"
"github.com/onsi/ginkgo/v2"
"github.com/pierrec/lz4"
"github.com/pkg/errors"
"github.com/pmezard/go-difflib"
"github.com/songgao/water"
"github.com/spf13/pflag"
"github.com/tadglines/go-pkgs"
"go.mozilla.org/pkcs7"
"go.uber.org/mock"
"golang.org/x/crypto"
"golang.org/x/exp"
"golang.org/x/mod"
"golang.org/x/net"
"golang.org/x/sync"
"golang.org/x/sys"
"golang.org/x/text"
"golang.org/x/time"
"golang.org/x/tools"
"golang.zx2c4.com/wintun"
"gopkg.in/yaml.v3"
"gvisor.dev/gvisor"
"software.sslmate.com/src/go-pkcs12"
)
echo "Checking which packages are directly imported in .go files..."
echo ""
for pkg in "${packages[@]}"; do
# Escape dots and slashes for regex
escaped=$(echo "$pkg" | sed 's/\./\\./g')
# Search for import statements in .go files (excluding vendor and test files for cleaner output)
matches=$(rg -t go --no-heading -n "\"$escaped" -g '!vendor/**' -g '!**/*_test.go' | head -5)
if [ -n "$matches" ]; then
echo "✓ $pkg - FOUND (directly imported)"
echo "$matches" | head -3
echo ""
else
echo "✗ $pkg - NOT FOUND (likely should be marked // indirect)"
fi
done
echo ""
echo "To verify and fix, run: go mod tidy"Repository: mobile-next/mobilecli
Length of output: 2736
🏁 Script executed:
#!/bin/bash
cd "$(git rev-parse --show-toplevel)" || exit 1
packages=(
"al.essio.dev/pkg/shellescape"
"github.com/Masterminds/semver"
"github.com/cenkalti/backoff"
"github.com/davecgh/go-spew"
"github.com/go-task/slim-sprig"
"github.com/godbus/dbus/v5"
"github.com/google/btree"
"github.com/google/pprof"
"github.com/grandcat/zeroconf"
"github.com/inconshreveable/mousetrap"
"github.com/kardianos/osext"
"github.com/miekg/dns"
"github.com/onsi/ginkgo/v2"
"github.com/pierrec/lz4"
"github.com/pkg/errors"
"github.com/pmezard/go-difflib"
"github.com/songgao/water"
"github.com/spf13/pflag"
"github.com/tadglines/go-pkgs"
"go.mozilla.org/pkcs7"
"go.uber.org/mock"
"golang.org/x/crypto"
"golang.org/x/exp"
"golang.org/x/mod"
"golang.org/x/net"
"golang.org/x/sync"
"golang.org/x/sys"
"golang.org/x/text"
"golang.org/x/time"
"golang.org/x/tools"
"golang.zx2c4.com/wintun"
"gopkg.in/yaml.v3"
"gvisor.dev/gvisor"
"software.sslmate.com/src/go-pkcs12"
)
echo "Checking direct imports in .go files (including *_test.go), excluding vendor..."
echo ""
for pkg in "${packages[@]}"; do
escaped=$(printf "%s" "$pkg" | sed 's/\./\\./g')
matches=$(rg -t go --no-heading -n "\"$escaped" -g '!vendor/**' | head -3)
if [ -n "$matches" ]; then
echo "✓ $pkg - FOUND"
echo "$matches"
echo ""
else
echo "✗ $pkg - NOT FOUND"
fi
doneRepository: mobile-next/mobilecli
Length of output: 1425
go.mod: revert/remove // indirect changes for unimported dependencies (go.mod lines 6-53)
Repo-wide scan found none of the listed modules being imported anywhere in non-vendored .go files (including *_test.go). Removing // indirect from these entries is therefore likely incorrect; run go mod tidy (or revert the dependency reorganization) to restore correct indirect/direct requirements.
🤖 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 `@go.mod` around lines 6 - 53, The go.mod changes removed or altered //
indirect markers for many modules (the entries shown) though none are directly
imported; restore correct indirect/direct annotations by reverting the
reorganization or running "go mod tidy" to regenerate go.mod and go.sum,
ensuring modules like github.com/Masterminds/semver, github.com/sirupsen/logrus,
golang.org/x/crypto, etc. return to their proper indirect status; verify the
go.mod matches the output of "go mod tidy" and commit that result.
Combines PR #240 (defer recover in handlers) with main's goroutine + semaphore pattern. Panic recovery now runs inside the handler goroutine, after the semaphore is acquired. Also updates go-ios to v1.0.211.
a panic in any handler propagated up and killed the process; defer recover logs the method name and stack trace, then sends a clean error response