Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@williammartin
Copy link
Contributor

@williammartin williammartin commented Jul 2, 2025

Description

Hey folks, while debugging gh cs ssh I noticed that ListTunnelPorts was returning the same port in every element of the slice. In a for loop, a new address is created for the loopvar. Appending the pointer of the loopvar to a slice means that every element in the slice will point to the last element ranged over.

TestTunnelListPorts in manager_test.go only checks that 2 ports were returning and doesn't interrogate the actual values, which is why this didn't fail. I would have updated the test but I didn't really want to figure out how to run them since they require a token.

I have no idea whether the tasks below are required for this change.

Other Tasks:

  • If you updated the Go SDK did you update the PackageVersion in tunnels.go
  • If you updated the TS SDK did you update the dependencies in package.json for connections and management to require a dependency that is > the current published version(Found using npm view @microsoft/dev-tunnels-contracts). This will fix issues where yarn will pull the old version of packages and will cause mismatched dependencies. See example PR

@williammartin
Copy link
Contributor Author

Gentle nudge on this @jasongin

@jasongin
Copy link
Member

@williammartin Thanks for the PR, sorry I missed it before.

I would have updated the test but I didn't really want to figure out how to run them sine they require a token.

Please do update the tests. To get a token, login with the CLI with verbose option:

devtunnel login -g --verbose

Your ghu_* GitHub token will be printed near the end of the output. Paste that token into the test getUserToken() function with "github" prefix.

If you updated the Go SDK did you update the PackageVersion in tunnels.go

Yes this is necessary. Please bump the package version, similar to how it was done in #447

I would do it, but I can't push to your fork, so I'd have to make a new PR.

Copy link
Member

@jasongin jasongin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the tests to verify the fixed port number, and bump the go package version.

@eimhin-rover
Copy link

Hey @williammartin have you had a chance to look at this? We are also hitting issues with some of our tooling that would be fixed with this change 🙏

In a for loop, a new address is created for the loopvar. Appending the
pointer of the loopvar to a slice means that every element in the slice
will point to the last element ranged over.
@williammartin williammartin force-pushed the wm/fix-list-tunnel-ports-go branch from a7900a1 to 31517c0 Compare August 25, 2025 14:24
@williammartin
Copy link
Contributor Author

@microsoft-github-policy-service agree company="GitHub"

@williammartin
Copy link
Contributor Author

Sorry folks, y'all responded right after I went on vacation. I believe I have addressed the outstanding concerns.

Failure

➜  dev-tunnels git:(wm/fix-list-tunnel-ports-go) ✗ go test -v ./go/tunnels -run TestTunnelListPorts
=== RUN   TestTunnelListPorts
2025/08/25 16:22:36 Created tunnel with id spiffy-river-clgktcs
Tunnel Properties
ClusterId           euw
TunnelId            spiffy-river-clgktcs
Name
Description
Labels              []
Access Control      {[]}
Ports
Host Connections    <nil>
Client Connections  <nil>
Available Scopes
2025/08/25 16:22:36 Created port: 3000
TunnelPort Properties
ClusterId              euw
TunnelId               spiffy-river-clgktcs
PortNumber             3000
Protocol               auto
Access Control         {[]}
Client Connections     &{0 1000  {0 0 {}}}
Last Connection Time   <nil>
2025/08/25 16:22:37 Created port: 3001
TunnelPort Properties
ClusterId              euw
TunnelId               spiffy-river-clgktcs
PortNumber             3001
Protocol               auto
Access Control         {[]}
Client Connections     &{0 1000  {0 0 {}}}
Last Connection Time   <nil>
    manager_test.go:658: port 3000 not successfully listed
2025/08/25 16:22:37 Port: 3001
TunnelPort Properties
ClusterId              euw
TunnelId               spiffy-river-clgktcs
PortNumber             3001
Protocol               auto
Access Control         {[]}
Client Connections     <nil>
Last Connection Time   <nil>
2025/08/25 16:22:37 Port: 3001
TunnelPort Properties
ClusterId              euw
TunnelId               spiffy-river-clgktcs
PortNumber             3001
Protocol               auto
Access Control         {[]}
Client Connections     <nil>
Last Connection Time   <nil>
2025/08/25 16:22:38 Got tunnel with id spiffy-river-clgktcs
Tunnel Properties
ClusterId           euw
TunnelId            spiffy-river-clgktcs
Name
Description
Labels              []
Access Control      {[]}
Ports               3000 - auto, 3001 - auto
Host Connections    <nil>
Client Connections  &{0 20  {0 0 {}}}
Available Scopes
2025/08/25 16:22:38 Deleted tunnel with id spiffy-river-clgktcs
--- FAIL: TestTunnelListPorts (4.79s)
FAIL
FAIL    github.com/microsoft/dev-tunnels/go/tunnels     8.319s
FAIL

Success

➜  dev-tunnels git:(wm/fix-list-tunnel-ports-go) ✗ go test -v ./go/tunnels -run TestTunnelListPorts
=== RUN   TestTunnelListPorts
2025/08/25 16:23:35 Created tunnel with id giant-pond-td1trtw
Tunnel Properties
ClusterId           euw
TunnelId            giant-pond-td1trtw
Name
Description
Labels              []
Access Control      {[]}
Ports
Host Connections    <nil>
Client Connections  <nil>
Available Scopes
2025/08/25 16:23:37 Created port: 3000
TunnelPort Properties
ClusterId              euw
TunnelId               giant-pond-td1trtw
PortNumber             3000
Protocol               auto
Access Control         {[]}
Client Connections     &{0 1000  {0 0 {}}}
Last Connection Time   <nil>
2025/08/25 16:23:37 Created port: 3001
TunnelPort Properties
ClusterId              euw
TunnelId               giant-pond-td1trtw
PortNumber             3001
Protocol               auto
Access Control         {[]}
Client Connections     &{0 1000  {0 0 {}}}
Last Connection Time   <nil>
2025/08/25 16:23:38 Port: 3000
TunnelPort Properties
ClusterId              euw
TunnelId               giant-pond-td1trtw
PortNumber             3000
Protocol               auto
Access Control         {[]}
Client Connections     <nil>
Last Connection Time   <nil>
2025/08/25 16:23:38 Port: 3001
TunnelPort Properties
ClusterId              euw
TunnelId               giant-pond-td1trtw
PortNumber             3001
Protocol               auto
Access Control         {[]}
Client Connections     <nil>
Last Connection Time   <nil>
2025/08/25 16:23:38 Got tunnel with id giant-pond-td1trtw
Tunnel Properties
ClusterId           euw
TunnelId            giant-pond-td1trtw
Name
Description
Labels              []
Access Control      {[]}
Ports               3000 - auto, 3001 - auto
Host Connections    <nil>
Client Connections  &{0 20  {0 0 {}}}
Available Scopes
2025/08/25 16:23:39 Deleted tunnel with id giant-pond-td1trtw
--- PASS: TestTunnelListPorts (6.80s)
PASS
ok      github.com/microsoft/dev-tunnels/go/tunnels     12.425s

@williammartin williammartin requested a review from jasongin August 25, 2025 14:44
@jasongin jasongin merged commit fab4fe7 into microsoft:main Aug 25, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants