balena tunnel: device not found (device is active, other CLI commands work)

Hi,

I’m trying to tunnel into a new device and balena tunnel is returning a BalenaDeviceNotFound error, but other CLI commands (balena ssh, balena logs) are working fine. The same balena tunnel command works fine for other devices.

The device in question is 8250417657ed63757d41cbad57fa7102. Not sure if it’s relevant, but it happens to be the only device we’ve tried so far where the UUID starts with a number instead of a letter.

I granted support access to the device if someone wants to take a look.

Thanks,

Adam

Hello I have no issues opening a tunnel with balena tunnel 8250417657ed63757d41cbad57fa7102 -p 80:8000.
Which version of the cli are you using ?

Huh, just got it working with the complete UUID:

~> balena --version
12.14.10

~> balena tunnel 8250 -p 80:8000 -p 8888:8888 -p 3000:3000 -p 22222:22222
BalenaDeviceNotFound: Device not found: 8250

~> balena tunnel 8250417657ed63757d41cbad57fa7102 -p 80:8000 -p 8888:8888 -p 3000:3000 -p 22222:22222
[Info]    Opening a tunnel to 8250417657ed63757d41cbad57fa7102...
[Info]     - tunnelling localhost:8000 to 8250417657ed63757d41cbad57fa7102:80
[Info]     - tunnelling localhost:8888 to 8250417657ed63757d41cbad57fa7102:8888
[Info]     - tunnelling localhost:3000 to 8250417657ed63757d41cbad57fa7102:3000
[Info]     - tunnelling localhost:22222 to 8250417657ed63757d41cbad57fa7102:22222
[Info]    Waiting for connections...

Not sure why the shortened UUID didn’t work though? It works just fine for other devices (e.g., c444 for device c444494394dde4718c97da4ed524ec3a).

I experimented a bit. Looks like the query requires a minimum of one non-numeric character and gives different errors for different inputs:

~> balena tunnel 8250417 -p 80:8000 -p 8888:8888 -p 3000:3000 -p 22222:22222
BalenaDeviceNotFound: Device not found: 8250417

~> balena tunnel 8250417657 -p 80:8000 -p 8888:8888 -p 3000:3000 -p 22222:22222
BalenaRequestError: Request error: Database error

Additional information may be available with the `--debug` flag.
For help, visit our support forums: https://forums.balena.io
For bug reports or feature requests, see: https://github.com/balena-io/balena-cli/issues/


~> balena tunnel 8250417657e -p 80:8000 -p 8888:8888 -p 3000:3000 -p 22222:22222
[Info]    Opening a tunnel to 8250417657ed63757d41cbad57fa7102...
[Info]     - tunnelling localhost:8000 to 8250417657ed63757d41cbad57fa7102:80
[Info]     - tunnelling localhost:8888 to 8250417657ed63757d41cbad57fa7102:8888
[Info]     - tunnelling localhost:3000 to 8250417657ed63757d41cbad57fa7102:3000
[Info]     - tunnelling localhost:22222 to 8250417657ed63757d41cbad57fa7102:22222
[Info]    Waiting for connections...

Thank you for reporting this, I’ve created a pull request to fix this, the next cli version should no longer have this bug.
PR: https://github.com/balena-io/balena-cli/pull/2004

Awesome, glad you found it so quickly.

Hi @adamshapiro0, I’d like to let you know that the bug has been resolved and we’ve merged this PR: https://github.com/balena-io/balena-cli/pull/2004.

Awesome, thanks for the update! I’ll try to give it a shot later today.

On a slightly related note, I know device names technically don’t have to be unique, but it would be extremely helpful if the CLI commands had the option to use device names instead of hashes. For example, try to interpret as a hash, and if not try as a device name. If the name isn’t unique, issue an error of some sort. I brought this up previously (Assign re-flashed device to existing UUID/name?) but the uniqueness was the concern at the time.

It’s way easier as a developer to look at a CLI command and be sure it’s the device you meant to use by name than to have to go remember which hash is which. This morning, for example, I briefly looked at the logs for the wrong device by accident and was wondering why my changes weren’t taking. If I had used the human-friendly device name in the CLI command instead of a hash, it would have been much more obvious what was wrong. We currently make sure our device names are unique so conflicts aren’t problem.

What do you think? Happy to start another thread.

Hi Adam, thanks for the suggestion. I’ll bring it up with the product team and let you know how it goes.

Hi Adam, I had a quick chat internally and unfortunately this is not something that we will be adding to the CLI. We feel that although identifying devices by name would make the tool more intuitive, making it fail if there is a clash (or offering a user UUID selection) is not really a good solution and will make the command not scriptable.

Hey @alexgg, I appreciate you folks considering it. I do agree that using device names could cause problems if using the CLI in a script and not properly handling the error condition. Not really sure I would agree that it should be a showstopper since people can and should just use UUIDs in scripts, but I understand the thinking.

Cheers,

Adam

FYI @alexgg and anyone who happens to come across this thread, we created an open source CLI wrapper to work around the issue and let you use device IDs for commands. See https://forums.balena.io/t/run-balena-cli-commands-by-device-name-instead-of-uuid.