danijel3 / KaldiWebrtcServer

Python server for communicating with Kaldi from the browser using WebRTC
Apache License 2.0
67 stars 37 forks source link

Huge memory consumption by server #5

Open RafNie opened 4 years ago

RafNie commented 4 years ago

Hi @danijel3 There is problem with huge memory consumption by the server in some situations. I debug it a little bit and I found that it is caused by wrong connection handling in case of errors in __audio_task. At example: When the client side starts the stream and after a moment stops it for some time and finally run streaming again, then the server starts consuming RAM with linear speed until all memory in the system is used. It is caused by such masked exception:

Traceback (most recent call last):
  File "/server/kaldi.py", line 72, in __run_audio_xfer
    frame = self.__resampler.resample(frame)
  File "av/audio/resampler.pyx", line 39, in av.audio.resampler.AudioResampler.resample
  File "av/audio/resampler.pyx", line 123, in av.audio.resampler.AudioResampler.resample
ValueError: Input frame pts 55137600 != expected 55133760; fix or set to None.

I prepared fix for that which improved connection handling in case of exceptions.