-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dotnetspy panic on premature exit and add tests. (#203)
There is a case when dotnetspy couldn't establish a connection to Diagnostics Server before the next snapshot/stop call (e.g, target process exited, or the socket file cannot be found, etc). This fix adds a check whether the session has been actually created before accessing it. Given that there are no race conditions between reset/stop/snapshot calls, redundant mutexes were removed.
- Loading branch information
1 parent
0f526ea
commit b2fff2b
Showing
4 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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,15 @@ | ||
// +build dotnetspy | ||
|
||
package dotnetspy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDotnetSpy(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, ".NET Spy Suite") | ||
} |
This file contains 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,36 @@ | ||
// +build dotnetspy | ||
|
||
package dotnetspy | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("agent.DotnetSpy", func() { | ||
Describe("Does not panic if a session has not been established", func() { | ||
s := newSession(31337) | ||
s.timeout = time.Millisecond * 10 | ||
Expect(s.start()).To(HaveOccurred()) | ||
spy := &DotnetSpy{session: s} | ||
|
||
It("On Snapshot before Reset", func() { | ||
spy.Snapshot(func(name []byte, samples uint64, err error) { | ||
Fail("Snapshot callback must not be called") | ||
}) | ||
}) | ||
|
||
It("On Snapshot after Reset", func() { | ||
spy.Reset() | ||
spy.Snapshot(func(name []byte, samples uint64, err error) { | ||
Fail("Snapshot callback must not be called") | ||
}) | ||
}) | ||
|
||
It("On Stop", func() { | ||
Expect(spy.Stop()).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains 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