Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb173195

Browse files
authored
Revert "fix: detect JetBrains running on local ipv6 (#11653)" (#11664)
This reverts commit2d61d53.
1 parent2aa3cbb commitb173195

File tree

3 files changed

+31
-65
lines changed

3 files changed

+31
-65
lines changed

‎agent/agent_test.go

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -214,59 +214,46 @@ func TestAgent_Stats_Magic(t *testing.T) {
214214
_,b,_,ok:=runtime.Caller(0)
215215
require.True(t,ok)
216216
dir:=filepath.Join(filepath.Dir(b),"../scripts/echoserver/main.go")
217+
echoServerCmd:=exec.Command("go","run",dir,
218+
"-D",agentssh.MagicProcessCmdlineJetBrains)
219+
stdout,err:=echoServerCmd.StdoutPipe()
220+
require.NoError(t,err)
221+
err=echoServerCmd.Start()
222+
require.NoError(t,err)
223+
deferechoServerCmd.Process.Kill()
217224

218-
spawnServer:=func(networkstring) (string,*exec.Cmd) {
219-
echoServerCmd:=exec.Command("go","run",dir,
220-
network,"-D",agentssh.MagicProcessCmdlineJetBrains)
221-
stdout,err:=echoServerCmd.StdoutPipe()
222-
require.NoError(t,err)
223-
err=echoServerCmd.Start()
224-
require.NoError(t,err)
225-
t.Cleanup(func() {
226-
echoServerCmd.Process.Kill()
227-
})
228-
229-
// The echo server prints its port as the first line.
230-
sc:=bufio.NewScanner(stdout)
231-
sc.Scan()
232-
returnsc.Text(),echoServerCmd
233-
}
234-
235-
port4,cmd4:=spawnServer("tcp4")
236-
port6,cmd6:=spawnServer("tcp6")
225+
// The echo server prints its port as the first line.
226+
sc:=bufio.NewScanner(stdout)
227+
sc.Scan()
228+
remotePort:=sc.Text()
237229

238230
//nolint:dogsled
239231
conn,_,stats,_,_:=setupAgent(t, agentsdk.Manifest{},0)
240-
deferconn.Close()
241-
242232
sshClient,err:=conn.SSHClient(ctx)
243233
require.NoError(t,err)
244234

245-
tunnel4,err:=sshClient.Dial("tcp4",fmt.Sprintf("127.0.0.1:%s",port4))
246-
require.NoError(t,err)
247-
defertunnel4.Close()
248-
249-
tunnel6,err:=sshClient.Dial("tcp6",fmt.Sprintf("[::]:%s",port6))
235+
tunneledConn,err:=sshClient.Dial("tcp",fmt.Sprintf("127.0.0.1:%s",remotePort))
250236
require.NoError(t,err)
251-
defertunnel6.Close()
237+
t.Cleanup(func() {
238+
// always close on failure of test
239+
_=conn.Close()
240+
_=tunneledConn.Close()
241+
})
252242

253243
require.Eventuallyf(t,func()bool {
254244
s,ok:=<-stats
255245
t.Logf("got stats with conn open: ok=%t, ConnectionCount=%d, SessionCountJetBrains=%d",
256246
ok,s.ConnectionCount,s.SessionCountJetBrains)
257247
returnok&&s.ConnectionCount>0&&
258-
s.SessionCountJetBrains==2
248+
s.SessionCountJetBrains==1
259249
},testutil.WaitLong,testutil.IntervalFast,
260250
"never saw stats with conn open",
261251
)
262252

263253
// Kill the server and connection after checking for the echo.
264-
requireEcho(t,tunnel4)
265-
requireEcho(t,tunnel6)
266-
_=cmd4.Process.Kill()
267-
_=cmd6.Process.Kill()
268-
_=tunnel4.Close()
269-
_=tunnel6.Close()
254+
requireEcho(t,tunneledConn)
255+
_=echoServerCmd.Process.Kill()
256+
_=tunneledConn.Close()
270257

271258
require.Eventuallyf(t,func()bool {
272259
s,ok:=<-stats

‎agent/agentssh/portinspection_supported.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package agentssh
44

55
import (
6-
"errors"
76
"fmt"
87
"os"
98

@@ -12,33 +11,24 @@ import (
1211
)
1312

1413
funcgetListeningPortProcessCmdline(portuint32) (string,error) {
15-
acceptFn:=func(s*netstat.SockTabEntry)bool {
14+
tabs,err:=netstat.TCPSocks(func(s*netstat.SockTabEntry)bool {
1615
returns.LocalAddr!=nil&&uint32(s.LocalAddr.Port)==port
16+
})
17+
iferr!=nil {
18+
return"",xerrors.Errorf("inspect port %d: %w",port,err)
1719
}
18-
tabs,err:=netstat.TCPSocks(acceptFn)
19-
tabs6,err6:=netstat.TCP6Socks(acceptFn)
20-
21-
// Only return the error if the other method found nothing.
22-
if (err!=nil&&len(tabs6)==0)|| (err6!=nil&&len(tabs)==0) {
23-
return"",xerrors.Errorf("inspect port %d: %w",port,errors.Join(err,err6))
20+
iflen(tabs)==0 {
21+
return"",nil
2422
}
2523

26-
varproc*netstat.Process
27-
iflen(tabs)>0 {
28-
proc=tabs[0].Process
29-
}elseiflen(tabs6)>0 {
30-
proc=tabs6[0].Process
31-
}
32-
ifproc==nil {
33-
// Either nothing is listening on this port or we were unable to read the
34-
// process details (permission issues reading /proc/$pid/* potentially).
35-
// Or, perhaps /proc/net/tcp{,6} is not listing the port for some reason.
24+
// Defensive check.
25+
iftabs[0].Process==nil {
3626
return"",nil
3727
}
3828

3929
// The process name provided by go-netstat does not include the full command
4030
// line so grab that instead.
41-
pid:=proc.Pid
31+
pid:=tabs[0].Process.Pid
4232
data,err:=os.ReadFile(fmt.Sprintf("/proc/%d/cmdline",pid))
4333
iferr!=nil {
4434
return"",xerrors.Errorf("read /proc/%d/cmdline: %w",pid,err)

‎scripts/echoserver/main.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,10 @@ import (
99
"io"
1010
"log"
1111
"net"
12-
"os"
1312
)
1413

1514
funcmain() {
16-
network:=os.Args[1]
17-
varaddressstring
18-
switchnetwork {
19-
case"tcp4":
20-
address="127.0.0.1"
21-
case"tcp6":
22-
address="[::]"
23-
default:
24-
log.Fatalf("invalid network: %s",network)
25-
}
26-
l,err:=net.Listen(network,address+":0")
15+
l,err:=net.Listen("tcp","127.0.0.1:0")
2716
iferr!=nil {
2817
log.Fatalf("listen error: err=%s",err)
2918
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp