Skip to content

Commit

Permalink
fix shutdown hang when enable socket (#835) (#845)
Browse files Browse the repository at this point in the history
* fix shutdown hang when enable socket

Signed-off-by: Loong <[email protected]>

* feedback

Signed-off-by: Loong <[email protected]>

Co-authored-by: Loong <[email protected]>
Co-authored-by: Mukundan Sundararajan <[email protected]>

Co-authored-by: Long Dai <[email protected]>
Co-authored-by: Loong <[email protected]>
Co-authored-by: Mukundan Sundararajan <[email protected]>
  • Loading branch information
4 people authored Nov 29, 2021
1 parent de0d2a4 commit 3287fa2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 4 additions & 0 deletions pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func Put(httpPort int, key, value, appID, socket string) error {
}

defer r.Body.Close()
if socket != "" {
// Retryablehttp does not close idle socket connections.
defer client.HTTPClient.CloseIdleConnections()
}
return nil
}

Expand Down
19 changes: 8 additions & 11 deletions tests/e2e/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const (
daprDashboardVersion = "0.9.0"
)

// Removing unix domain socket tests till shutdown API with unix domain sockets is fixed.
// https://github.com/dapr/dapr/issues/3894
var socketCases = []string{""}
var socketCases = []string{"", "/tmp"}

func TestStandaloneInstall(t *testing.T) {
// Ensure a clean environment.
Expand Down Expand Up @@ -382,14 +380,13 @@ func testRun(t *testing.T) {
assert.Contains(t, output, "Exited Dapr successfully")
})

// t.Run("API shutdown with socket", func(t *testing.T) {
// // Test that the CLI exits on a daprd shutdown.
// output, err := spawn.Command(daprPath, "run", "--app-id", "testapp", "--unix-domain-socket", "/tmp", "--", "bash", "-c", "curl --unix-socket /tmp/dapr-testapp-http.socket -v -X POST http://unix/v1.0/shutdown; sleep 10; exit 1")
// t.Log(output)
// require.NoError(t, err, "run failed")
// assert.Contains(t, output, "Exited App successfully", "App should be shutdown before it has a chance to return non-zero")
// assert.Contains(t, output, "Exited Dapr successfully")
// })
t.Run("API shutdown with socket", func(t *testing.T) {
// Test that the CLI exits on a daprd shutdown.
output, err := spawn.Command(daprPath, "run", "--app-id", "testapp", "--unix-domain-socket", "/tmp", "--", "bash", "-c", "curl --unix-socket /tmp/dapr-testapp-http.socket -v -X POST http://unix/v1.0/shutdown; sleep 10; exit 1")
t.Log(output)
require.NoError(t, err, "run failed")
assert.Contains(t, output, "Exited Dapr successfully")
})
}

func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) {
Expand Down

0 comments on commit 3287fa2

Please sign in to comment.