Conversation
…-chain into gprusak-channel
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2582 +/- ##
==========================================
- Coverage 46.08% 44.16% -1.93%
==========================================
Files 1174 1796 +622
Lines 101716 149301 +47585
==========================================
+ Hits 46879 65941 +19062
- Misses 50738 77487 +26749
- Partials 4099 5873 +1774
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| // Remember to call OpenForAppend before Append. | ||
| // You need to call Sync afterwards to ensure entry is persisted on disk. | ||
| func (w *WAL) Append(msg WALMessage) error { | ||
| entry, err := proto.Marshal(&tmcons.TimedWALMessage{Time: time.Now(), Msg: msg.toProto()}) |
Check warning
Code scanning / CodeQL
Calling the system time Warning
| } | ||
| defer func() { | ||
| if resErr != nil { | ||
| f.Close() |
Check warning
Code scanning / CodeQL
Writable file handle closed without error handling Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the issue, ensure that errors returned by f.Close() in the deferred cleanup handler in openLogWriter are checked and returned appropriately. The fix should update the deferred function (starting at line 67 in openLogWriter) so that if f.Close() returns an error, it is propagated as the error for openLogWriter—but only if no prior error was already being returned (resErr).
This requires changing the function's signature to use named return values, e.g. (res *logWriter, resErr error), and then updating the deferred function to set resErr if it is nil and f.Close() returns an error.
No changes to imports or additional helpers are needed. The intention and functionality of the code remain unchanged: just more robust error reporting.
| @@ -66,7 +66,9 @@ | ||
| } | ||
| defer func() { | ||
| if resErr != nil { | ||
| f.Close() | ||
| if err := f.Close(); err != nil && resErr == nil { | ||
| resErr = err | ||
| } | ||
| } | ||
| }() | ||
| // Truncate the file to non-corrupted prefix and sync. |
There was a problem hiding this comment.
f.Close() closes the descriptor, even if an error is returned. This is the only property this code needs.
| } | ||
|
|
||
| group, err := auto.OpenGroup(ctx, logger, walFile, groupOptions...) | ||
| inner, err := wal.OpenLog(walFile, wal.DefaultConfig()) |
There was a problem hiding this comment.
Nice, this seems to be much simpler and cleaner than the previous autofile approach
New implementation uses the same representation as the old one, so it is backward compatible.