alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.35k stars 1.04k forks source link

Segmentation fault on recognizer.close() in Java #1556

Open olafth opened 2 months ago

olafth commented 2 months ago

I have a RSocket channel, send data and recognition works. On resource cleanup, specifically on recognizer.close a SIGSEGV happens. I am using VoskApi 0.3.45 and also compiled the current master (0.3.48) and installed libvosk.so in /usr/lib. No changes. OS is Kubuntu 22.04. The SIGSEGV happens both with a self written RSocket client and rsc.jar and the commandline java -jar rsc.jar --debug --channel --load ./de_1.wav --route audio.bytes.de tcp://localhost:7000


# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007b51a67e791f, pid=60565, tid=62882
#
# JRE version: OpenJDK Runtime Environment (17.0.10+13) (build 17.0.10+13-LTS)
# Java VM: OpenJDK 64-Bit Server VM (17.0.10+13-LTS, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C  [jna18035368486101055434.tmp+0x3e791f]  kaldi::LatticeIncrementalDecoderTpl<fst::Fst<fst::ArcTpl<fst::TropicalWeightTpl<float> > >, kaldi::decoder::BackpointerToken>::~LatticeIncrementalDecoderTpl()+0x1f
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /home/otho/IdeaProjects/VoskServer/Thor11Asr/core.60565)
#
# An error report file with more information is saved as:
# /home/[...]/hs_err_pid60565.log
_malloc_consolidate(): invalid chunk size_```
olafth commented 2 months ago

I found the problem. It happens when the recognizer is not disposed of correctly. This should definitely raise an exception, but a SIGSEGV is a bit much :)

cmrkgj commented 3 weeks ago

Have you solved your problem?

olafth commented 3 weeks ago

Yes. In my comment on April 25th I mentioned the resolution. It happens when the vosk recognizer is not disposed of correctly. If you use it in a try-with-resources block like try (InputStream inputStream = is; Recognizer recognizer = rec) {...} the problem does not occur.