RMS icon indicating copy to clipboard operation
RMS copied to clipboard

sqlite3.OperationalError: database is locked

Open aitov opened this issue 3 months ago • 3 comments

Hi, today I faced this issue second time on UA0001 camera, the first time was after big release so it is rare but sometimes happening and as result - no captured data for this night Maybe it could be somehow fixed.

The error log:

Traceback (most recent call last):
  File "/home/pi/source/RMS/RMS/BufferedCapture.py", line 1198, in initVideoDevice
    max_retries=5, retry_interval=1
  File "/home/pi/source/RMS/RMS/BufferedCapture.py", line 934, in createGstreamDevice
    device_url = self.extractRtspUrl(self.config.deviceID)
  File "/home/pi/source/RMS/RMS/BufferedCapture.py", line 580, in extractRtspUrl
    raise ValueError("No RTSP URL found in the input string: {}".format(input_string))
ValueError: No RTSP URL found in the input string: v4l2src device=/dev/video0 !  videoconvert ! video/x-raw,format=GRAY8 ! appsink sync=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/source/RMS/RMS/BufferedCapture.py", line 1569, in run
    while not self.exit.is_set() and not self.initVideoDevice():
  File "/home/pi/source/RMS/RMS/BufferedCapture.py", line 1261, in initVideoDevice
    conn = getObsDBConn(self.config)
  File "/home/pi/source/RMS/RMS/Formats/ObservationSummary.py", line 96, in getObsDBConn
    """SELECT name FROM sqlite_master WHERE type = 'table' and name = 'records';""").fetchall()
sqlite3.OperationalError: database is locked

aitov avatar Sep 03 '25 06:09 aitov

I'm also seeing the same issue on some systems. I'll put it on the stack, hopefully someone can look into it.

dvida avatar Sep 04 '25 11:09 dvida

Hi, Small analysis from me: the root cause : connection locked by: ObservationSummary.startObservationSummaryReport I checked db for this date and see that insertion to table records very slow (maybe sd card overloaded) and insert of all parameters takes - 12 seconds.

Possible solutions

  • get connection with bigger timeout (default is 5 sec)
  • add retry logic in case if db locked (i.e. 6 times - 30sec)
  • add try/catch in place where it happened to continue capture process, but we lost media_backend parameter in this case

If some one can advise what is the best option - I can prepare pull request with fix.

place for try/catch :

 except Exception as e:
                    log.info("Error initializing GStreamer, switching to alternative. Error: {}".format(e))
                    self.media_backend_override = True
                    self.releaseResources()

                 add here --->  conn = getObsDBConn(self.config)
                    addObsParam(conn, "media_backend", self.video_device_type)
                    conn.close()

Times from DB:

Image

aitov avatar Sep 12 '25 08:09 aitov

Thanks for the report, I'll start looking into it.

g7gpr avatar Sep 15 '25 20:09 g7gpr

Still working on this.

g7gpr avatar Dec 21 '25 08:12 g7gpr