Skip to content

fix(errkit): return ErrKindUnknown from Kind without storing it - #828

Open
dwisiswant0 wants to merge 1 commit into
mainfrom
dwisiswant0/fix/errkit/return-errkindunknown-from-kind-without-storing-it
Open

dwisiswant0 wants to merge 1 commit into
mainfrom
dwisiswant0/fix/errkit/return-errkindunknown-from-kind-without-storing-it

Conversation

@dwisiswant0

Copy link
Copy Markdown
Member

When an error had no kind, Kind() assigned ErrKindUnknown to e.kind
before returning it, so the getter wrote to its receiver. An *ErrorX
is often a package-level sentinel read from many goroutines, and
concurrent Kind() calls on one raced on that interface field. The
write also changed the error: parseError copies the kind into every
error that wraps the sentinel, so after one Kind() call those errors
reported unknown-error instead of no kind. Errors given a kind with
SetKind never reached the assignment, which is why they did not race.

Return the fallback without storing it, as Kind() did before bb8871e,
and document on ErrorX that only its setters modify it, so the other
methods stay safe to call on a shared error.

fastdialer calls Kind() on every dial error it returns, so the dial
errors it leaves unclassified used to carry ErrKindUnknown and now
carry no kind, which GetErrorKind reports as an empty kind (#827).
For those errors, GetErrorKind and the kind field in nuclei's error
log change from "unknown-error" to "", IsKind(err, ErrKindUnknown)
returns false, and GetAllErrorKinds stops listing ErrKindUnknown
next to a kind it detects. IsKind against any other kind returns
what it did before.

Fixes: #826
Refs: #827

When an error had no kind, Kind() assigned ErrKindUnknown to e.kind
before returning it, so the getter wrote to its receiver. An *ErrorX
is often a package-level sentinel read from many goroutines, and
concurrent Kind() calls on one raced on that interface field. The
write also changed the error: parseError copies the kind into every
error that wraps the sentinel, so after one Kind() call those errors
reported unknown-error instead of no kind. Errors given a kind with
SetKind never reached the assignment, which is why they did not race.

Return the fallback without storing it, as Kind() did before bb8871e,
and document on ErrorX that only its setters modify it, so the other
methods stay safe to call on a shared error.

fastdialer calls Kind() on every dial error it returns, so the dial
errors it leaves unclassified used to carry ErrKindUnknown and now
carry no kind, which GetErrorKind reports as an empty kind (#827).
For those errors, GetErrorKind and the kind field in nuclei's error
log change from "unknown-error" to "", IsKind(err, ErrKindUnknown)
returns false, and GetAllErrorKinds stops listing ErrKindUnknown
next to a kind it detects. IsKind against any other kind returns
what it did before.

Fixes: #826
Refs: #827
Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 added this pull request to stack #830 November 10, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

errkit: concurrent Kind() calls on the same error report a data race

1 participant