planetscale/cli

[Feature Request] Do not disconnect `pscale` CLI on CTRL+C

Closed this issue · 5 comments

In the CLI, I often find myself wanting to clear a command I was entering with Ctrl+C. That leads to either a disconnect or my terminal hanging in a weird limbo state. It'd be nice if it just cleared the current command I was about to send, and let me enter a new one.

(I would be perfectly fine with having to hit Ctrl+C twice to disconnect in those cases that I already started typing something.)

The new behaviour seems to be broken:

  1. I enter a query (select foo) without submitting. I hit Ctrl+C. ^C appears and I can enter a new query. So far, so good.
  2. I enter a new query (select count(*) from SomeTable) and hit ↵ Enter to submit it. ^C appears again, and my query (apparently) doesn't get submitted. This is wrong; I expected my query to be submitted.
  3. I enter the query again and submit it. I get a response.
$ pscale shell database branch
database/branch> select foo^C
database/branch> select count(*) from SomeTable;
^C
database/branch> select count(*) from SomeTable;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
database/branch> 

Ctrl+D does work, although it takes up to a few seconds and sometimes produces some errors:

org/branch> ^Dfailed to delete credentials:  Delete "https://api.planetscale.com/v1/organizations/account/databases/org/branches/branch/passwords/asdfgh123456": context deadline exceeded
Error: os: process already finished

Versions:

  • pscale version 0.195.0 (build date: 2024-04-18T15:27:49Z commit: e37d329)
  • bash version 5.2.26(1)-release
  • GNOME Terminal version 3.48.3 for GNOME 44
  • Fedora 38

2. I enter a new query (select count(*) from SomeTable) and hit ↵ Enter to submit it. ^C appears again, and my query (apparently) doesn't get submitted. This is wrong; I expected my query to be submitted.

For some reason I'm not sure about yet, Go seems to double deliver the signals which is why this seems to be happening. I see the interrupt being delivered twice instead of once, so I have to find out why that's the case. That's the cause of this issue, since the second one is then also interrupted due to the double delivery.

Ctrl+D does work, although it takes up to a few seconds and sometimes produces some errors:

It is expected it takes some time to shut down. That it wasn't doing this before is a bug that was fixed. The message it prints something to fix though.

The reason for shutdown taking some time is that we create dynamic credentials for the proxy to be able to run mysql and those credentials should be cleaned up, which happens in an API call.

For me it takes less than a second though, but this is dependent on your connection latency, speed etc. for how fast those API calls execute.

For some reason I'm not sure about yet, Go seems to double deliver the signals which is why this seems to be happening. I see the interrupt being delivered twice instead of once, so I have to find out why that's the case. That's the cause of this issue, since the second one is then also interrupted due to the double delivery.

Alright, see #854 for why this was happening and the fix (this is about process groups receiving ctrl+c by default, so hence double delivery with the existing signals setup).

@twiddler If you install the latest release, things should be working a lot better now!

Works like a charm. Thank you so much!