fix(plugin): register executor in pluginMap and enable gRPC in Serve#1946
fix(plugin): register executor in pluginMap and enable gRPC in Serve#1946pameican wants to merge 1 commit intodkron-io:mainfrom
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip You can disable the changed files summary in the walkthrough.Disable the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/serve.go`:
- Around line 40-50: Add defensive validation at the start of the Serve
function: check if the incoming ServeOpts pointer is nil and return a clear
error (or panic with an explicit message) rather than dereferencing it; after
building the plugins map (using ProcessorPluginName/ExecutorPluginName and types
ProcessorPlugin/ExecutorPlugin) validate that at least one plugin was registered
and return a descriptive error if the map is empty to fail fast on all-nil
configuration. Ensure the checks reference ServeOpts, ProcessorPluginName,
ExecutorPluginName, ProcessorPlugin and ExecutorPlugin so callers get an
immediate, explicit failure instead of a later panic or unclear error.
| plugins := map[string]plugin.Plugin{} | ||
|
|
||
| if opts.Processor != nil { | ||
| plugins[ProcessorPluginName] = &ProcessorPlugin{Processor: opts.Processor} | ||
| } | ||
|
|
||
| if opts.Executor != nil { | ||
| plugins[ExecutorPluginName] = &ExecutorPlugin{Executor: opts.Executor} | ||
| } | ||
|
|
||
| return plugins |
There was a problem hiding this comment.
Add defensive validation for ServeOpts to avoid panic/misconfiguration paths.
At Line 42 and Line 46, opts is dereferenced without a nil check. Serve(nil) will panic, and all-nil ServeOpts creates an empty plugin map that can fail later with less-clear errors. Consider failing fast with an explicit message.
Suggested hardening
func Serve(opts *ServeOpts) {
+ if opts == nil {
+ panic("plugin: ServeOpts must not be nil")
+ }
+ plugins := pluginMap(opts)
+ if len(plugins) == 0 {
+ panic("plugin: at least one plugin (processor or executor) must be configured")
+ }
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: Handshake,
- Plugins: pluginMap(opts),
+ Plugins: plugins,
GRPCServer: plugin.DefaultGRPCServer,
})
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@plugin/serve.go` around lines 40 - 50, Add defensive validation at the start
of the Serve function: check if the incoming ServeOpts pointer is nil and return
a clear error (or panic with an explicit message) rather than dereferencing it;
after building the plugins map (using ProcessorPluginName/ExecutorPluginName and
types ProcessorPlugin/ExecutorPlugin) validate that at least one plugin was
registered and return a descriptive error if the map is empty to fail fast on
all-nil configuration. Ensure the checks reference ServeOpts,
ProcessorPluginName, ExecutorPluginName, ProcessorPlugin and ExecutorPlugin so
callers get an immediate, explicit failure instead of a later panic or unclear
error.
|
@pameican Dkron already has many external plugins and they work out of the box, verify your plugin's code, use the ones in the project as starting point and your plugin should work. Or do you mean something else? |
|
Hi @vcastellm, you're right, sorry for the noise. After checking the builtin plugins (like My plugin was incorrectly using Once I aligned my That said, Thanks for the quick response! |
Problem
External executor plugins always crash on startup with:
This makes it impossible to use any custom executor plugin with dkron v4.
Root cause
Two bugs in
plugin/serve.go:1. Missing
GRPCServerinServe()plugin.Serve()was called withoutGRPCServer: plugin.DefaultGRPCServer. Thego-pluginlibrary defaults tonetrpcwhen no gRPC server is configured. Since dkron v4 only accepts gRPC, every external plugin is rejected at handshake time.2.
pluginMap()never registers the executorpluginMap()only registers"processor"and ignores"executor", despiteServeOpts.ExecutorandExecutorPluginNamebeing defined. Any plugin callingServe()with anExecutoris silently ignored — the plugin map is empty for its type.Fix
Tested
Verified with a custom executor plugin (
dkron-executor-secrethttp) running on dkron v4.0.9 on Kubernetes (AKS).CrashLoopBackOffwithunsupported plugin protocol "netrpc"Running, jobs executing correctlySummary by CodeRabbit