File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
"os"
20
20
"strconv"
21
21
"syscall"
22
+ "time"
22
23
)
23
24
24
25
func activateAttachAPI (pid int ) error {
@@ -44,13 +45,26 @@ func activateAttachAPI(pid int) error {
44
45
return fmt .Errorf ("could not send signal 3 to activate attach API: %w" , err )
45
46
}
46
47
47
- // TODO: Poll a few milliseconds to ensure the socket is active?
48
+ // Check if the UNIX socket is active
49
+ sock := socketPath (pid )
50
+ for i := 1 ; i < 10 ; i ++ {
51
+ if _ , err := os .Stat (sock ); err != nil && ! os .IsNotExist (err ) {
52
+ break
53
+ }
54
+
55
+ // exponential backoff
56
+ time .Sleep (time .Duration (1 << uint (i )) * time .Millisecond )
57
+ }
48
58
49
59
return nil
50
60
}
51
61
62
+ func socketPath (pid int ) string {
63
+ return fmt .Sprintf ("/proc/%v/root/tmp/.java_pid%v" , pid , pid )
64
+ }
65
+
52
66
func connect (pid int ) (* net.UnixConn , error ) {
53
- sock := fmt . Sprintf ( "/proc/%v/root/tmp/.java_pid%v" , pid , pid )
67
+ sock := socketPath ( pid )
54
68
55
69
// Check if the UNIX socket is active
56
70
if _ , err := os .Stat (sock ); err != nil && os .IsNotExist (err ) {
You can’t perform that action at this time.
0 commit comments