<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>13181</bug_id>
          
          <creation_ts>2019-02-14 19:11:25 +0000</creation_ts>
          <short_desc>persist_data sqlite database mixed with forking is irreparably broken</short_desc>
          <delta_ts>2026-03-18 21:43:06 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>6.1 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joshua Watt">JPEWhacker</reporter>
          <assigned_to name="Unassigned">unassigned</assigned_to>
          <cc>liezhi.yang</cc>
    
    <cc>mostthingsweb</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>tgamblin</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>83010</commentid>
    <comment_count>0</comment_count>
    <who name="Joshua Watt">JPEWhacker</who>
    <bug_when>2019-02-14 19:11:25 +0000</bug_when>
    <thetext>The current persist_data uses a sqlite database that is shared among all the threads that wish to access it. The bitbake worker processes that spawn off are forked off of other processes which are also accessing the database, which causes the underlying sqlite database object to be cloned into the new child process. Once this is done, the game is over however because while the python sqlite state and underlying file descriptor are copied to the new process, the POSIX advisory locks that it had aren&apos;t. This means that there is essential no record to any other process that the new child exists and needs to be synchronized with other sqlite connections. This can cause all sorts of synchronization problems since the database pages might get flushed, or even worse unmapped from memory while the &quot;hidden&quot; child process is trying to read from it (this is the specific case I found; the child processes were dying with a SIGBUS error in sqlite).

sqlite admits this is a problem a little more succinctly and recommends that if you *must* carry an open connection across a fork(), you immediately close() (not sqlite3_close()!) the underlying file descriptor: https://www.sqlite.org/howtocorrupt.html#_carrying_an_open_database_connection_across_a_fork_ . However, python being what it is, this isn&apos;t a very tenable solution since 
1) we don&apos;t have direct access to the underlying file descriptor
2) couldn&apos;t prevent python from garbage collecting the sqlite database object
3) The os.register_at_fork() API wasn&apos;t added until Python 3.7
4) Even if the os.register_at_fork() handler was available, it&apos;s a pretty ugly hack.

Note that this problem probably isn&apos;t biting us at all currently because of the read-only and single process nature of the persist_data; that is data is mostly only read and only done so by a single process, but this is likely to change with https://bugzilla.yoctoproject.org/show_bug.cgi?id=13030 .

I believe that the best long term solution is to rework persist data to use a client server model where a single server process handles the sqlite database and manages requests on behalf of the clients.

I&apos;ve started incubating a python module that can do such a thing efficiently for  read-mostly uses cases using shared memory here: https://github.com/JPEWdev/pyradur</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96062</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-07-26 21:21:59 +0000</bug_when>
    <thetext>Bulk move of 64 bugs to 4.3 M3 after a quick review.
If a bug is actually fixed, please add a commit link and resolve it.
-- Randy for YP bug team.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96450</commentid>
    <comment_count>2</comment_count>
    <who name="Trevor Gamblin">tgamblin</who>
    <bug_when>2023-09-14 15:56:01 +0000</bug_when>
    <thetext>Moved to M4.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97051</commentid>
    <comment_count>3</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-10-30 15:29:07 +0000</bug_when>
    <thetext>Bulk move to 5.0 M1. -- Randy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97659</commentid>
    <comment_count>4</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-12-21 23:28:25 +0000</bug_when>
    <thetext>Bulk move of 52 5.0-M1 bugs to M2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97986</commentid>
    <comment_count>5</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2024-01-25 14:28:44 +0000</bug_when>
    <thetext>Bulk move of bugs owned by &quot;unassigned&quot; from 5.0-M2 to 5.0-M3.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98297</commentid>
    <comment_count>6</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2024-02-22 19:53:22 +0000</bug_when>
    <thetext>Bulk move of bugs from 5.0-M3 to 5.99.
The bugs in this list are all unassigned and are ones that I consider to be nice to do some time but not essential track from milestone to milestone in 5.0 or 5.1. We agreed on this bug handling approach in the YP bug review on Feb 22, 2024.

If you disagree, please move back to a 5.[012...]-M* milestone.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104707</commentid>
    <comment_count>7</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2026-03-18 21:43:06 +0000</bug_when>
    <thetext>Optimistically moving to 6.1-M1, albeit as unassigned.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>