harlequin: Quitting with a non-empty buffer causes hang on restart
Before Proceeding, please acknowledge:
- I have consulted the Troubleshooting guide.
- I have searched Issues and Discussions in this repo.
- Feature requests should be initiated as Discussions. This is a bug report.
Describe the bug
If the editor is closed with the quit keybinding with a non-empty buffer, future restarts of harlequin hang. I think this is cache related as deleting the harlequin cache directory fixes this.
To Reproduce
- Start harlequin
- Type something in the editor
- Quit (
^qor otherwise) - Start harlequin
Expected behavior Harlequin should run normally on second invocation.
Actual behavior Harlequin hangs on second invocation.
Contributing Are you interested in contributing a fix?
- Yes
- Maybe
- No
Additional context
I can load the cache locally after stopping harlequin using the load_cache() method, so the cache isn’t corrupted. If I use the methods to clear the editor cache, harlequin also behaves normally.
What is the output of harlequin --version?
What database adapter are you using with Harlequin? (Default is duckdb)
This occurs with duckdb and postgres.
What other options are you using when invoking Harlequin? (If you are using a profile, please add relevant items from your profile here).
Just postgres connection details & limits for duckdb.
Can you tell us more about your system?
- Shell: Zsh
- Terminal: Alacritty
- OS of the shell: Void Linux (also seen on Arch Linux)
- OS of the terminal (if different from the shell): -
- Default locale / language for your OS/Terminal/Shell: en_GB.UTF-8
[!TIP] For example, for my system, these are:
- Bash
- Windows Terminal
- Ubuntu 22.04 / WSL2
- Windows 11
- en_US/UTF-8
How did you install Harlequin?
- pipx
- conda/mamba
- pip (global install)
- pip + venv/virtualenv or pipenv
- Poetry
- uv/Rye
- other: _____________
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (10 by maintainers)
I have a branch with the upgrade, and can confirm it fixes this issue; unfortunately it introduces a few new ones, and it’ll take me some time to iron that out. (Time I don’t have today)
I can also reliably reproduce this with uv / pipx installed Harlequin on MacOS. The thing I noticed, is it’s not deadlocking, it’s hanging with 100% CPU. I used
py-spyto get a thread dump which shows it’s spinning in this function:Rich 13.9.2 was released ~2 weeks ago and mentions a fix to “split_cells”: https://github.com/Textualize/rich/releases/tag/v13.9.2 - suspiciously around the time these reports started coming in.
Downgrading rich to 13.9.1 seems to fix it for me.
[edit] I think this is the problem/fix: https://github.com/Textualize/rich/issues/3532
Yeah, it’s even weirder than that – it can restore the cache if the cache is only whitespace (including newlines). But if you have a selection or non-whitespace characters, the packaged version can’t restore the cache, and just hangs.
@TLipede Pickle was just a convenience.
Given WHEN this is hanging (and what I wrote above), I suspect we’re reading from the cache file fine, and it’s hanging when the CodeEditor/TextArea is being initialized with some text.