apache / apache/pulsar

[Bug] Ctrl-C does not terminating the current shell operation in pulsar shell

Open
#22,671 2 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Read release policy

- [X] I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

### Version

3.2.2

### Minimal reproduce step

**Issue Description:**
In the Pulsar-Shell environment, when a user presses Ctrl-C during a shell operation to terminate the running shell operation, an exception `org.apache.pulsar.shell.PulsarShell$InterruptShellException` occurs but it does not terminate the running shell operation, it prints the below stack trace and the current execution keeps on running. Ideally, it should terminate the current execution.
```
^CException in thread "SIGINT handler" org.apache.pulsar.shell.PulsarShell$InterruptShellException
at org.apache.pulsar.shell.PulsarShell.lambda$run$2(PulsarShell.java:230)
at org.jline.terminal.impl.AbstractTerminal.raise(AbstractTerminal.java:89)
at org.jline.terminal.impl.PosixSysTerminal.lambda$handle$1(PosixSysTerminal.java:65)
at org.jline.utils.Signals.lambda$register$1(Signals.java:53)
at jdk.proxy2/jdk.proxy2.$Proxy3.handle(Unknown Source)
at jdk.unsupported/sun.misc.Signal$InternalMiscHandler.handle(Signal.java:198)
at java.base/jdk.internal.misc.Signal$1.run(Signal.java:219)
at java.base/java.lang.Thread.run(Thread.java:840)
```

**To reproduce it locally:**

- Run pulsar in standalone mode.
- Start pulsar-shell using `./bin/pulsar-shell`
- Run some command for example, `client produce my-topic -m "my-msg" -n 1000` or `client consume -s s1 my-topic -n 1000`
- Then try to press Ctrl+C immediately. The expected behaviour should be that it terminate the above command immediately and return to the shell terminal. But it will print the above stack trace instead and keeps running the command till it finishes producing 1000 messages or till it finishes consuming 1000 messages respectively.

### What did you expect to see?

When the user presses Ctrl-C to terminate the currently running shell operation it should terminate the current execution and return to the shell terminal.

### What did you see instead?

On pressing Ctrl-C during a shell operation, the current shell operation keeps on running. In addition, it also prints the below stack trace:
```
^CException in thread "SIGINT handler" org.apache.pulsar.shell.PulsarShell$InterruptShellException
at org.apache.pulsar.shell.PulsarShell.lambda$run$2(PulsarShell.java:230)
at org.jline.terminal.impl.AbstractTerminal.raise(AbstractTerminal.java:89)
at org.jline.terminal.impl.PosixSysTerminal.lambda$handle$1(PosixSysTerminal.java:65)
at org.jline.utils.Signals.lambda$register$1(Signals.java:53)
at jdk.proxy2/jdk.proxy2.$Proxy3.handle(Unknown Source)
at jdk.unsupported/sun.misc.Signal$InternalMiscHandler.handle(Signal.java:198)
at java.base/jdk.internal.misc.Signal$1.run(Signal.java:219)
at java.base/java.lang.Thread.run(Thread.java:840)
```

### Anything else?

This [PR](https://github.com/apache/pulsar/pull/18615/files) is related which fixes #19218.

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start in PulsarShell.java around line 230 and reproduce the issue with pulsar-shell using the client produce or consume commands described above. Trace how the SIGINT handler affects the running shell operation, then verify that Ctrl-C returns to the shell without printing the InterruptShellException stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.