-
Notifications
You must be signed in to change notification settings - Fork 422
Closed
Description
Version 5.2.3 introduced a regression that causes "file already closed" errors when reading key files. This affects both regular files and process substitution. The issue is also present on the latest v5.3.0.
Steps to Reproduce
# works with v5.2.2
$ echo '{"user":"admin"}' | jwt -key priv.key -alg ES512 -sign -
eyJhbGciOiJFUzUx...
# fails with v5.2.3
$ echo '{"user":"admin"}' | jwt -key priv.key -alg ES512 -sign -
Error: couldn't read key: read priv.key: file already closed
# Same with process substitution
# works with v5.2.2
$ echo '{"user":"admin"}' | jwt -key <(cat priv.key) -alg ES512 -sign -
eyJhbGciOiJFUzUx...
# fails with v5.2.3
$ echo '{"user":"admin"}' | jwt -key <(cat priv.key) -alg ES512 -sign -
Error: couldn't read key: read /proc/self/fd/13: file already closedExpected Behavior
The command should successfully read the key file and output the JWT.
Actual Behavior
Error: couldn't read key: read priv.key: file already closed
Or with process substitution:
Error: couldn't read key: read /proc/self/fd/13: file already closed
Environment
- jwt: v5.2.3
- Go: 1.24.4 linux/amd64
- OS: Void Linux
- Shell: bash 5.2.32
Root Cause
The issue appears to be caused by 12384ea#diff-fd1ad9799c0a3eec351605e9d9411bcdd7da014a2e5da1e95209a6f5d49adb97L94-R96 where defer f.Close() was replaced with immediate f.Close(), causing the file to be closed before the read operation completes.
Metadata
Metadata
Assignees
Labels
No labels