Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop in TerminalLine constructor #751

Closed
loveleif opened this issue Nov 19, 2021 · 2 comments
Closed

Infinite loop in TerminalLine constructor #751

loveleif opened this issue Nov 19, 2021 · 2 comments
Milestone

Comments

@loveleif
Copy link

The constructor of LineReaderImpl$TerminalLine can go into an infinite loop under certain circumstances.

It seems to be caused by width being zero. We have seen it when using jansi in the following environments:

  • Docker version 18.03.1-ce (works after updating docker).
  • Running tests through maven on OSX with custom input/output streams for the terminal.
@loveleif
Copy link
Author

I will try to re-create the issue in a small example project and get back.

@loveleif
Copy link
Author

loveleif commented Nov 23, 2021

Here is an example project that will cause the infinite loop in certain environments when you run mvn test https://github.com/loveleif/jline-infinate-loop.

It happens on my machine and I use:

  • macOS 12.0.1
  • Apache Maven 3.8.3
  • Java 17 (OpenJDK build 17+35-2724)

Note: Without .variable( LineReader.SECONDARY_PROMPT_PATTERN, "%P " ) it doesn't go into infinite loop.

@Test
void test() throws IOException
{
    var in = new ByteArrayInputStream( "hello\nworld\n".getBytes( StandardCharsets.UTF_8 ) );
    var out = new ByteArrayOutputStream(1024);

    var terminal = TerminalBuilder.builder().streams( in, out ).build();
    var lineReader = LineReaderBuilder.builder()
            .terminal( terminal )
            .variable( LineReader.SECONDARY_PROMPT_PATTERN, "%P " )
            .build();

    var read1 = lineReader.readLine("Input1: ");
    var read2 = lineReader.readLine("Input2: ");

    assertEquals( "hello", read1 );
    assertEquals( "world", read2 );
}

neo-technology-build-agent pushed a commit to neo4j/neo4j that referenced this issue Dec 6, 2021
This is an attempt to workaround a bug in jline that causes an infinite loop
sometimes [1]. We have seen it in osx when running maven tests and we have seen
it out in the wild on an old version of docker.

[1] jline/jline3#751
@mattirn mattirn closed this as completed in 4dac9b0 Jun 3, 2022
@gnodet gnodet added this to the 3.22.0 milestone Jan 16, 2023
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

No branches or pull requests

2 participants