ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
963 stars 35 forks source link

info.updateTerminalSize() can crash on MacOS Ventura #86

Open corbym opened 1 year ago

corbym commented 1 year ago

Firstly let me thank you for this amazing lib AND cliktcommand. They are super useful :)

However, apart from not really working (as you can see from the video, all the tables get squashed to nothing), the jvm updateTerminalSize function causes the JVM to crash on MacOs Ventura:

hs_err_pid22892.log

replay_pid77535.log

Crash log on console out:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000010469021c, pid=77535, tid=23299
#
# JRE version: OpenJDK Runtime Environment GraalVM CE 22.3.0 (17.0.5+8) (build 17.0.5+8-jvmci-22.3-b08)
# Java VM: OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (17.0.5+8-jvmci-22.3-b08, mixed mode, sharing, tiered, jvmci, jvmci compiler, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# V  [libjvm.dylib+0x75021c]  MethodMatcher::matches(methodHandle const&) const+0x44
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/mattcorby-eaglen/repos/binder/applications/connect-cli/hs_err_pid77535.log
> #
# Compiler replay data is saved as:
# /[redacted]/replay_pid77535.log

https://user-images.githubusercontent.com/21261837/215809290-46b5b510-2efc-4294-b787-9f843283e627.mov

All this command I'm running is calling the updateTerminalSize function in a CliktCommand underneath. I'm adapting the mordant terminal using the interfaces provided for Clikt, if you are wondering, and everything works fine in a linux docker environment.

Edit:

> java -version
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)

Second edit: added console crash message for GraalVm and replay log

ajalt commented 1 year ago

I can't really read the text in that video. Can you post the crash text and the code that reproduces this?

It's strange that it works for a while. This is tricky since I don't have a mac machine to test on, and this doesn't look like I'll be able to reproduce it in a unit test on CI.

corbym commented 1 year ago

Hey

The same crash text is in the hs_err log attached I think.

If that doesn't help I'll post it when I get back to my laptop tomorrow 👍

ajalt commented 1 year ago

Ah, thanks, I missed that in the original post.

Does this crash only occur under Graal? Does it work on a regular JVM?

corbym commented 1 year ago

On the HotSpot JVM the crash is as follows:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000014754ac14, pid=75088, tid=5635
#
# JRE version: Java(TM) SE Runtime Environment (17.0.6+9) (build 17.0.6+9-LTS-190)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0.6+9-LTS-190, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# j  jdk.proxy2.$Proxy2.ioctl(ILcom/sun/jna/NativeLong;Lcom/github/ajalt/mordant/internal/MacosLibC$winsize;)I+27 jdk.proxy2
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# [redacted]/hs_err_pid75088.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp

HotSpot hs_err_pid hs_err_pid75088.log

java details:

> java -version
java version "17.0.6" 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
corbym commented 1 year ago

Possibly related? https://github.com/jline/jline3/issues/688 - there are several linked issues that might be worth reading about.

I do use JLine (v3.22.0), but not to discover or update anything regarding the size of the terminal.

ajalt commented 1 year ago

@corbym great find! I implemented the ioctl from the linked issue in #87. Let me know if that fixes the crash.

nfsantos commented 1 year ago

Hello. I'm having a problem that may be related. I'm on M1 MacBook Pro running Ventura. Calling updateTerminalSize does not crash in my machine but instead fails to detect the size of the terminal (it returns false). The size is left to 79 x 24, which makes all the tables and formatting in general too small. This problem only occurs with version 2.0.0-beta10 and 2.0.0-beta11. With 2.0.0-beta9 and earlier, the detection of the terminal size works fine.

Do you think it is related to this issue or is it a separate issue?

ajalt commented 1 year ago

@nfsantos probably the same issue. Can you try the branch on #87 to see if it fixes your issue?

nfsantos commented 1 year ago

Sure, I can try. How should I do to try that branch? Is there a binary somewhere for that branch or do I have to build it locally?

ajalt commented 1 year ago

I just merged the PR, so you can use the latest snapshot once it finishes building.

nfsantos commented 1 year ago

I have tried with the latest snapshot release and it still failed to detect the terminal size. It fails in the same way as with 2.0.0-beta11, that is, updateTerminalSize() returns false. Shall I open a new issue? What additional information do you need to try to debug the issue?

$ ./gradew dependencies:
...
+--- com.github.ajalt.mordant:mordant:2.0.0-beta11.72-SNAPSHOT
|    \--- com.github.ajalt.mordant:mordant-jvm:2.0.0-beta11.72-SNAPSHOT
|         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0 (*)
|         +--- com.github.ajalt.colormath:colormath:3.2.1
|         |    \--- com.github.ajalt.colormath:colormath-jvm:3.2.1
|         |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10 -> 1.8.0 (*)
|         |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10 -> 1.8.0
|         +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0
|         +--- org.jetbrains:markdown:0.3.6
|         |    \--- org.jetbrains:markdown-jvm:0.3.6
|         |         +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31 -> 1.8.0
|         |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.31 -> 1.8.0 (*)
|         \--- net.java.dev.jna:jna:5.12.1
corbym commented 1 year ago

@ajalt Naive testing suggests that this has worked to fix the crash. However, changing the term size doesn't affect the numbers in the column. At least the size does not shrink to nothing any more :)

https://user-images.githubusercontent.com/21261837/218520449-52d519f7-7e86-4a8d-a437-714460bbfdfb.mov

ajalt commented 1 year ago

I just released a new version of Mordant that reverts to the old detectTerminalSize implementation for now. I'm leaving this issue open until we can figure out how to get it working with jna. Let me know if it still doesn't work.