Commit c3afc8a
committed
fix: prevent crashes from missing keys and history records
Fix unhandled promise rejections and crashes caused by race conditions
in WalletConnect message processing. These changes prevent Lambda
timeouts and 502 errors by gracefully handling expected edge cases.
Changes:
1. crypto.decode() - Handle missing symmetric keys gracefully
- Wrap generateSharedKey() in try-catch (was outside, causing crashes)
- Return undefined on decode failure instead of throwing
- Change error logging to warn (expected race condition)
2. history.resolve() - Handle missing history records gracefully
- Wrap getRecord() in try-catch to prevent crashes
- Log warnings instead of errors for missing records
- Continue processing other messages when record not found
3. engine.onRelayMessage() - Handle undefined payload from decode
- Check for undefined payload after decode
- Early return with warning if decode fails
- Prevents downstream crashes from undefined values
4. engine.onRelayEventResponse() - Handle missing history records
- Wrap history.get() in try-catch
- Early return with warning if record not found
- Prevents crashes when response arrives before request recorded
These fixes address stack traces showing:
- "No matching key. history: <id>" errors
- "onRelayMessage() -> failed to process inbound message" errors
- Lambda 502 "Internal Server Error" responses
All changes maintain backward compatibility and use appropriate
log levels (warn for expected race conditions, error for unexpected).1 parent d203cf1 commit c3afc8a
File tree
3 files changed
+32
-16
lines changed- packages
- core/src/controllers
- sign-client/src/controllers
3 files changed
+32
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1987 | 1987 | | |
1988 | 1988 | | |
1989 | 1989 | | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
1990 | 1995 | | |
1991 | 1996 | | |
1992 | 1997 | | |
| |||
2089 | 2094 | | |
2090 | 2095 | | |
2091 | 2096 | | |
2092 | | - | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
2093 | 2104 | | |
2094 | 2105 | | |
2095 | 2106 | | |
| |||
0 commit comments