Skip to content

fix: no return after nil check#112

Merged
rustatian merged 3 commits intomasterfrom
fix/panic-when-no-plugin
Mar 6, 2026
Merged

fix: no return after nil check#112
rustatian merged 3 commits intomasterfrom
fix/panic-when-no-plugin

Conversation

@rustatian
Copy link
Copy Markdown
Member

@rustatian rustatian commented Mar 6, 2026

Reason for This PR

Description of Changes

  • Fix NPE, reason: no return after nil check.
  • Add test for that case.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • Bug Fixes

    • Jobs endpoint now properly returns an error when the jobs plugin is missing, preventing unexpected failures.
  • Documentation

    • Added package docs describing HTTP endpoints (/health, /ready, /jobs) and RPC methods for monitoring plugin health and readiness.
  • Chores

    • CI workflow improved for coverage artifact handling and summary generation.
    • Dependency updates and code cleanup.
  • Tests

    • Expanded test suite with extensive handler and RPC scenarios, including shutdown and missing-plugin cases.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian self-assigned this Mar 6, 2026
@rustatian rustatian added the enhancement New feature or request label Mar 6, 2026
Copilot AI review requested due to automatic review settings March 6, 2026 20:46
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 6, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds a nil-guard to the Jobs HTTP handler to avoid panics, updates API imports/types to v6 status packages, replaces a toPtr helper with new(bool), introduces extensive tests for status handlers (including /jobs without plugin), and adjusts CI coverage artifact handling and docs.

Changes

Cohort / File(s) Summary
CI/CD Workflow
.github/workflows/linux.yml
Added checkout steps before artifact downloads; switched download-artifact from v8→v7 with explicit name/path; updated coverage summary filtering via awk and adjusted codecov upload to use generated summary.txt.
Package docs & tests metadata
doc.go, tests/doc.go
Added package-level documentation for the status plugin and test package header describing endpoints and RPCs.
Jobs handler
jobs.go
Added early return when statusJobsRegistry is nil to prevent nil-pointer dereference in Jobs.ServeHTTP.
Plugin initialization
plugin.go
Replaced toPtr(...) usage with new(bool) and removed the toPtr helper; adjusted imports to v6 api-plugins.
RPC signatures
rpc.go
Updated RPC method signatures to use status/v2 types (StatusRequest/StatusResponse).
Tests (new/updated)
handler_test.go, tests/plugin_test.go, tests/...
Added extensive handler tests (health, ready, jobs), new JobsEndpointWithoutPlugin test asserting 503, updated tests to use v2 status types, added fuzz tests and nil/cleanup checks.
PHP test deps
tests/php_test_files/composer.json
Upgraded Guzzle to ^7.0 and swapped Guzzle adapter to php-http/guzzle7-adapter.
Module deps
go.mod, tests/go.mod
Swapped legacy api v4 dependency for v6 beta modules (api-go/v6, api-plugins/v6), added/adjusted test deps (testify, indirects).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #2310: Fixes the nil-pointer panic in Jobs.ServeHTTP by adding a guard for missing statusJobsRegistry and adds tests exercising the /jobs endpoint when the plugin is absent.

Possibly related PRs

  • status#65: Related changes to shutdown handling and status plugin fields (similar import/type updates and shutdown flag handling).

Suggested labels

bug

Suggested reviewers

  • wolfy-j

Poem

🐰 I hopped through code both night and day,
Found a nil-guard hiding in the way.
Tests now guard the /jobs gate wide,
Docs and CI march by my side.
sniff — hop, ship, and restful pride!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Multiple substantial changes beyond the core nil-check fix are present: API version upgrades (v4→v6), dependency updates, test infrastructure changes, and workflow updates that may be scope-creep. Clarify whether API upgrades and dependency changes are necessary for the NPE fix or should be split into separate PRs to isolate the core bug fix.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: no return after nil check' accurately describes the main change: adding a return statement after a nil check in jobs.go to fix a nil pointer dereference bug.
Description check ✅ Passed The PR description includes the issue reference, clear explanation of the fix (NPE prevention), test coverage confirmation, and all PR checklist items marked as complete.
Linked Issues check ✅ Passed The PR addresses the core requirements from issue #2310: fixes the nil pointer dereference in jobs.go by adding a return after the nil check, and includes a test case (JobsEndpointWithoutPlugin) for the error scenario.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/panic-when-no-plugin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a nil-pointer panic in the /jobs status endpoint when the jobs plugin is not registered (issue #2310), and adds coverage around that behavior.

Changes:

  • Add missing return after writing an error response in the /jobs handler to prevent dereferencing a nil registry.
  • Add an integration test that asserts /jobs returns 503 with “jobs plugin not found” when the jobs plugin is absent.
  • Update CI plumbing for coverage artifact download/filtering and adjust PHP test dependencies.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
jobs.go Prevents NPE by returning immediately after the nil-registry error response.
tests/plugin_test.go Adds an integration test covering /jobs when jobs plugin is not registered.
plugin.go Refactors shutdown flag pointer initialization (currently introduces a compile error).
tests/php_test_files/composer.json Updates PHP deps for tests (moves to Guzzle 7 + adapter).
.github/workflows/linux.yml Adjusts codecov job to download coverage artifact into a directory and filter paths.
doc.go Adds package-level documentation for the status plugin.
tests/doc.go Adds package documentation for the integration tests package.
go.work.sum Updates workspace sums due to dependency changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugin.go
Comment thread plugin.go
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.97%. Comparing base (9d17cdd) to head (eb39408).

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #112       +/-   ##
===========================================
+ Coverage        0   53.97%   +53.97%     
===========================================
  Files           0        6        +6     
  Lines           0      365      +365     
===========================================
+ Hits            0      197      +197     
- Misses          0      138      +138     
- Partials        0       30       +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/linux.yml (1)

98-105: Awk filter silently drops coverage lines that don't match the expected prefix.

The awk script only prints lines matching the github.com/roadrunner-server/status/v5/ prefix pattern. Any coverage lines from other packages or with different paths will be silently discarded. If the coverage file contains only lines from this package, this is fine, but it could cause unexpected data loss otherwise.

Consider printing all non-header lines while still stripping the prefix from matching ones:

♻️ Suggested improvement to preserve all coverage lines
          awk '
            NR == 1 { print; next }
-           /^github\.com\/roadrunner-server\/status\/v5\// {
-             sub(/^github\.com\/roadrunner-server\/status\/v5\//, "", $0)
-             print
-           }
+           {
+             sub(/^github\.com\/roadrunner-server\/status\/v5\//, "", $0)
+             print
+           }
          ' summary.txt > summary.filtered.txt
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/linux.yml around lines 98 - 105, The current awk block
that processes summary.txt only emits lines matching the prefix and drops other
non-header lines; update the awk script (the multi-line awk in the workflow that
reads summary.txt and writes summary.filtered.txt) so that it still prints the
header (NR==1) and then for every subsequent line: if it matches the prefix
"github.com/roadrunner-server/status/v5/" strip that prefix and print, otherwise
print the line unchanged — this preserves all coverage lines while still
removing the unwanted prefix when present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@plugin.go`:
- Line 84: Replace the invalid uses of new(false)/new(true) when storing into
the atomic pointer shutdownInitiated: change the false case to use new(bool) to
obtain a *bool for c.shutdownInitiated.Store, and for the true case introduce
package-level bool variables (e.g. _true and _false) and use their addresses
(&_true / &_false) in the calls to c.shutdownInitiated.Store so the method
receives a proper *bool; update the two locations that call
c.shutdownInitiated.Store accordingly (the line initializing shutdown to false
and the line setting it to true).
- Line 130: The code uses new(true)/new(false) which is invalid in Go; change
calls to c.shutdownInitiated.Store(...) to pass a *bool by creating a local bool
variable and taking its address (e.g., b := true;
c.shutdownInitiated.Store(&b)), and apply the same pattern where
shutdownInitiated is initialized with false (e.g., b := false;
c.shutdownInitiated.Store(&b)) so Store receives a *bool; update both the
initialization site and the shutdown trigger (the uses of new(false) and
new(true)) accordingly.

---

Nitpick comments:
In @.github/workflows/linux.yml:
- Around line 98-105: The current awk block that processes summary.txt only
emits lines matching the prefix and drops other non-header lines; update the awk
script (the multi-line awk in the workflow that reads summary.txt and writes
summary.filtered.txt) so that it still prints the header (NR==1) and then for
every subsequent line: if it matches the prefix
"github.com/roadrunner-server/status/v5/" strip that prefix and print, otherwise
print the line unchanged — this preserves all coverage lines while still
removing the unwanted prefix when present.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04c04503-aef9-421f-b26c-f85e6f7bffec

📥 Commits

Reviewing files that changed from the base of the PR and between 9d17cdd and eb39408.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • .github/workflows/linux.yml
  • doc.go
  • jobs.go
  • plugin.go
  • tests/doc.go
  • tests/php_test_files/composer.json
  • tests/plugin_test.go

Comment thread plugin.go
Comment thread plugin.go
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian merged commit 16cf502 into master Mar 6, 2026
5 of 7 checks passed
@rustatian rustatian deleted the fix/panic-when-no-plugin branch March 6, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 BUG]: ttp: panic serving <ip>:51581: runtime error: invalid memory address or nil pointer dereference

2 participants