Open fricpa opened 1 month ago
for now, I have created a private fork of this repo and removed all Thread based functionality (scan thread, reader thread); now the same infinite loop never crashes the program
FWIW, with hid4java:0.8.0 I also did get a fatal error/crash on Windows 10 at least once now, hs err attached
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd41751b40, pid=22844, tid=27032
#
# JRE version: OpenJDK Runtime Environment Temurin-11.0.23+9 (11.0.23+9) (build 11.0.23+9)
# Java VM: OpenJDK 64-Bit Server VM Temurin-11.0.23+9 (11.0.23+9, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C 0x00007ffd41751b40
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
# https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
with the threadless version I cannot reproduce this anymore; there must be some thread safety concerns that are violated by the current implementation
I would be fairly cautious interacting with libhidapi.so and even with JNA in anything but a single-threaded or at least serialized fashion...
Here's a reference for hidapi not being thread-safe: https://github.com/libusb/hidapi/wiki
FAQ hidapi is not thread-safe in general. How to use hidapi in multithreaded application? https://github.com/libusb/hidapi/issues/45
Platform
Knowing the platform greatly narrows down the potential causes of the problem.
linux-arm32/64
, Raspberry Pi 3/4, amd64arm32,
bookworm` arm64=aarch64, Ubuntu 24.04hid4java
version0.8.0
To Reproduce
Steps to reproduce the behavior:
Write a trivial program
let it run for a while on the specified platforms.
Expected behavior
Runs without issues forever.
Screenshots and logs
I observed three crash modes so far (note I have a littlescript running the app and logging some stuff, but the basic program is as above):
all of them often appear within a few minutes of running that loop, however, sometimes they don't appear for a long time or only after I plugged in some devices and read/wrote some data to them...
1.
2.
3.
or, on Ubuntu 24.04
Additional information I have not observed any of these failure modes on amd64 Windows 10, the loop seems to run forever there as it should.
However, on Linux it's definitely broken on every platform I tested.
It seems a lot of such issues can be caused by talking to native code from multiple java threads:
https://stackoverflow.com/questions/22491797/java-double-free-or-corruption https://stackoverflow.com/questions/49628615/understanding-corrupted-size-vs-prev-size-glibc-error
I don't quite understand why hid4java needs any threads in the first place
at least for my usecase, all I would need are synchronous enumeration, synchronous read & write (with timeout), all of which are synchronous calls in hidapi
fwiw I have attached the hs_err log files hs_err_pid2754.log hs_err_pid12909.log