Skip to content

Respect contexts with timeouts#1948

Merged
zricethezav merged 1 commit into
gitleaks:masterfrom
leaktk:ctx-timeout
Oct 24, 2025
Merged

Respect contexts with timeouts#1948
zricethezav merged 1 commit into
gitleaks:masterfrom
leaktk:ctx-timeout

Conversation

@bplaxco
Copy link
Copy Markdown
Contributor

@bplaxco bplaxco commented Sep 23, 2025

Description:

Today contexts with timeouts set aren't fully respected, this is adding some support for that so it's easier to bail out during larger scans.

Also I ran make format and it touched up a few other places.

Checklist:

  • Does your PR pass tests?
  • Have you written new tests for your changes?
  • Have you lint your code locally prior to submission?

@bplaxco bplaxco force-pushed the ctx-timeout branch 5 times, most recently from a8d7bfd to 8fd9677 Compare September 23, 2025 09:09
@bplaxco
Copy link
Copy Markdown
Contributor Author

bplaxco commented Sep 23, 2025

@zricethezav I think it should be good to go. I'm going to do a little extra testing but things initially looked good. Sorry for some of the noise in a few unrelated files. I updated the readme and that trimmed out some trailing whitespace on save and make format touched up a few files as well. Also some of the other changes look bigger than they actually are because blocks of code where indented for the select statements.

@bplaxco bplaxco marked this pull request as ready for review September 23, 2025 09:18
Comment thread sources/git.go
Comment on lines +424 to +430
select {
case <-ctx.Done():
return ctx.Err()
default:
wg.Wait()
return nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: what's the difference between this and doing if ctx.Err() != nil { return ctx.Err() }? Is there any reason why one is better than the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't played with it too deeply, but I've seen most of the examples for how to handle this use the select method. I think it does something special under the covers based on a few quirks I saw but I'd like to experiment with it more on the side to understand exactly what's happening and why select seems to be the way to go instead of just checking for err.

Also I'm not sure if there's ever a situation where ctx may be done but there not be an error 🤷 So I wouldn't be surprised either if it was just a semantic thing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes here, as far as I can tell?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no changes on notion.go, it was all make format touching whitespace.

@zricethezav
Copy link
Copy Markdown
Collaborator

@bplaxco would you mind resolving conflicts?

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
@zricethezav zricethezav merged commit c5ccbb9 into gitleaks:master Oct 24, 2025
2 checks passed
@bplaxco bplaxco deleted the ctx-timeout branch November 19, 2025 16:33
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.

3 participants