Skip to content

Conversation

@rMaxiQp
Copy link
Contributor

@rMaxiQp rMaxiQp commented Oct 27, 2025

Why the changes in this PR are needed?

When I stress test runtime unit tests, there are two errors surface:

  • too many opened files on startWatcher()
  • context deadline exceed on server shutdown

Checking fsnotify examples, a watcher.Close() is used to close the file which I failed to find in the current codebase. If we don't set GracefulShutdownPeriod, the default value would be 0, and the server must shutdown in 0s.

What are the changes in this PR?

  • Close watcher when the context is closed, similar as

    opa/cmd/test.go

    Lines 287 to 300 in e048c19

    select {
    case evt := <-watcher.Events:
    removalMask := fsnotify.Remove | fsnotify.Rename
    mask := fsnotify.Create | fsnotify.Write | removalMask
    if (evt.Op & mask) != 0 {
    removed := ""
    if (evt.Op & removalMask) != 0 {
    removed = evt.Name
    }
    processWatcherUpdate(ctx, testParams, paths, removed, store)
    }
    case <-done:
    _ = watcher.Close()
    return
  • Update NewParam() to have a default 1s GracefulShutdownPeriod to avoid immediate context expiry

Notes to assist PR review:

fix #7956

Further comments:

The original PR focused on closing watchers. However, seeing the broken CI leads me to the GracefulShutdownPeriod change, which is independent to watchers. The new fix is only a one-line update, and I amended the fix here. If it's better to keep them separate, I can create another PR for GracefulShutdownPeriod change as well.

@netlify
Copy link

netlify bot commented Oct 27, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 66cb5c5
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/68fed9dec92d820008938773
😎 Deploy Preview https://deploy-preview-7991--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Oct 27, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 9b4ba93
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/68ff9b98cb041300082a99dd
😎 Deploy Preview https://deploy-preview-7991--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rMaxiQp rMaxiQp changed the title fix: close runtime watcher on context.Done() fix runtime tests: close watcher & set default GracefulShutdownPeriod Oct 27, 2025
@sspaink
Copy link
Member

sspaink commented Oct 27, 2025

@rMaxiQp thank you for investigating this! This seems like a good change. Unfortunately it looks like the flaky test still failed in the first commit: https://github.com/open-policy-agent/opa/actions/runs/18828000270/job/53714056675

@rMaxiQp
Copy link
Contributor Author

rMaxiQp commented Oct 27, 2025

Hi @sspaink, thanks for the quick response. Yes, only having the watcher change resolved too many opened filed error, but not context deadline exceed. Which is why there is a second commit to address that. Since these two are independent changes, I left them as two separate commits.

Copy link
Member

@sspaink sspaink left a comment

Choose a reason for hiding this comment

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

Great work!

@sspaink sspaink merged commit bafd4db into open-policy-agent:main Oct 27, 2025
31 checks passed
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.

Flaky REPL test

2 participants