-
Notifications
You must be signed in to change notification settings - Fork 45
signals: enable hotreload on Windows via pipe #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JoshVanL
wants to merge
5
commits into
dapr:main
Choose a base branch
from
JoshVanL:signals-windows-pipe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //go:build !windows | ||
|
|
||
| /* | ||
| Copyright 2026 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package signals | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strconv" | ||
| "syscall" | ||
| ) | ||
|
|
||
| // ReloadPipeName returns the named pipe path used by a dapr process with the | ||
| // given PID to listen for reload signals on Windows. On POSIX systems this is | ||
| // not used (SIGHUP is used instead), but returns the same value as the Windows | ||
| // implementation so that cross-platform code can compute the expected name. | ||
| func ReloadPipeName(pid int) string { | ||
| return `\\.\pipe\dapr-reload-` + strconv.Itoa(pid) | ||
| } | ||
|
|
||
| // SignalReload sends SIGHUP to the process with the given PID on POSIX | ||
| // systems, triggering a runtime reload. | ||
| func SignalReload(pid int) error { | ||
| proc, err := os.FindProcess(pid) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to find process %d: %w", pid, err) | ||
| } | ||
|
|
||
| err = proc.Signal(syscall.SIGHUP) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to send SIGHUP to process %d: %w", pid, err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what the |
||
| Copyright 2026 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package signals | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/Microsoft/go-winio" | ||
| ) | ||
|
|
||
| // ReloadPipeName returns the named pipe path used by a dapr process with the | ||
| // given PID to listen for reload signals on Windows. This is exported so that | ||
| // external tooling (CLI, tests) can connect to trigger a reload. | ||
| func ReloadPipeName(pid int) string { | ||
| return `\\.\pipe\dapr-reload-` + strconv.Itoa(pid) | ||
| } | ||
|
|
||
| // listenPipe creates a Windows named pipe listener at the given path. | ||
| // The pipe is secured so that the creating user (Creator Owner), | ||
| // Built-in Administrators, and Local System have full access. | ||
| func listenPipe(name string) (net.Listener, error) { | ||
| return winio.ListenPipe(name, &winio.PipeConfig{ | ||
| // CO = Creator Owner, BA = Built-in Administrators, SY = Local System. | ||
| SecurityDescriptor: "D:P(A;;GA;;;CO)(A;;GA;;;BA)(A;;GA;;;SY)", | ||
| }) | ||
| } | ||
|
|
||
| // SignalReload connects to the reload named pipe for the given PID, triggering | ||
| // a reload of that dapr process. | ||
| func SignalReload(pid int) error { | ||
| pipeName := ReloadPipeName(pid) | ||
| timeout := 5 * time.Second | ||
| conn, err := winio.DialPipe(pipeName, &timeout) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to connect to reload pipe %s: %w", pipeName, err) | ||
| } | ||
| conn.Close() | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| Copyright 2026 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package signals | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestOnHUP_WindowsPipe(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| ctxCh := OnHUP(ctx) | ||
|
|
||
| // First context should be emitted immediately. | ||
| var firstCtx context.Context | ||
| select { | ||
| case c, ok := <-ctxCh: | ||
| require.True(t, ok, "channel should yield a context") | ||
| firstCtx = c | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("timed out waiting for initial context from OnHUP") | ||
| } | ||
|
|
||
| // First context should not be canceled yet. | ||
| assert.NoError(t, firstCtx.Err(), "initial context should not be canceled") | ||
|
|
||
| // Send a reload signal via the named pipe. | ||
| err := SignalReload(os.Getpid()) | ||
| require.NoError(t, err, "SignalReload should connect to the pipe") | ||
|
|
||
| // First context should be canceled after the reload signal. | ||
| select { | ||
| case <-firstCtx.Done(): | ||
| // expected | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("timed out waiting for first context to be canceled after reload signal") | ||
| } | ||
|
|
||
| // A new context should be emitted for the next reload cycle. | ||
| var secondCtx context.Context | ||
| select { | ||
| case c, ok := <-ctxCh: | ||
| require.True(t, ok, "channel should yield a second context") | ||
| secondCtx = c | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("timed out waiting for second context from OnHUP") | ||
| } | ||
|
|
||
| assert.NoError(t, secondCtx.Err(), "second context should not be canceled yet") | ||
|
|
||
| // Cancel the parent context to shut down the pipe listener. | ||
| cancel() | ||
|
|
||
| select { | ||
| case <-secondCtx.Done(): | ||
| // expected | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("timed out waiting for second context to be canceled after parent cancel") | ||
| } | ||
|
|
||
| // Channel should be closed after parent context cancellation. | ||
| select { | ||
| case _, ok := <-ctxCh: | ||
| assert.False(t, ok, "channel should be closed after parent context is canceled") | ||
| case <-time.After(5 * time.Second): | ||
| t.Fatal("timed out waiting for channel to close") | ||
| } | ||
| } | ||
|
|
||
| func TestReloadPipeName(t *testing.T) { | ||
| name := ReloadPipeName(12345) | ||
| assert.Equal(t, `\\.\pipe\dapr-reload-12345`, name) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.