ODBC.jl icon indicating copy to clipboard operation
ODBC.jl copied to clipboard

ReadOnlyMemoryError on first run after recompile

Open ahjulstad opened this issue 9 months ago • 0 comments

I am experiencing ReadOnlyMemoryError when reading the results of a query into a DataFrame.

Code excerpt:

const conn_str = "DRIVER={ODBC Driver 18 for SQL Server};SERVER=$server;DATABASE=$database;Uid=$username;Pwd=$password;Authentication=ActiveDirectoryServicePrincipal;Encrypt=yes;"

_getconnection() = ODBC.Connection(conn_str)

data = DBInterface.execute(_getconnection(), longquerystr) |> DataFrame

My overall code structure is following this suggestion, where I am using Revise and Oxygen to give me hot reload of server code.

This happens consistently if I do the following:

  • Stop Julia
  • Make any edit to the server module
  • Execute the server start script in VS CODE REPL
    • This starts Julia, triggers precompile, and launches the server, Oxygen then listens on http
  • Hit the endpoint triggering the query.
  • ReadOnlyMemoryError (stacktrace below)

A second trigger of the endpoint works fine. Updates to the server while running (that triggers Revise updates) works fine.

Then restarting Julia, running the server script again (which triggers recompile), and error happens again.

When preparing a minimal reproducible example I discovered that it also depends on the query. Trivial queries do not trigger the error, so perhaps the timing of the response from the server is influencing this. (I am hitting a Microsoft Fabric Warehouse SQL endpoint with ODBC). Also, some minor changes, like reading the query string from file just prior to launching the query stops the error from occurring. Some strange race condition, this.

As others won't have access to the same database I am hitting, it will be difficult for others to recreate the bug using the example, unfortunately.

Stacktrace:

┌ Error: ERROR:
│   exception =
│    ReadOnlyMemoryError()
│    Stacktrace:
│      [1] SQLFetchScroll(stmt::Ptr{Nothing}, fetch_orientation::Int16, fetch_offset::Int64)
│        @ ODBC.API C:\Users\ahju\.julia\packages\ODBC\9VZTC\src\API.jl:67
│      [2] iterate(x::ODBC.Cursor{false, false}, st::Int64)
│        @ ODBC C:\Users\ahju\.julia\packages\ODBC\9VZTC\src\dbinterface.jl:387
│      [3] iterate
│        @ C:\Users\ahju\.julia\packages\ODBC\9VZTC\src\dbinterface.jl:387 [inlined]
│      [4] iterate
│        @ .\iterators.jl:206 [inlined]
│      [5] iterate
│        @ .\iterators.jl:205 [inlined]
│      [6] buildcolumns(schema::Tables.Schema{¤¤¤¤¤¤¤¤¤ redacted), Tuple{Union{Missing, String}, Union{Missing, String}, Union{Missing, String}, Union{Missing, String}, Union{Missing, Int32}, Vararg{Union{Missing, String}, 6}}}, rowitr::ODBC.Cursor{false, false})
│        @ Tables C:\Users\ahju\.julia\packages\Tables\NSGZI\src\fallbacks.jl:146
│      [7] _columns
│        @ C:\Users\ahju\.julia\packages\Tables\NSGZI\src\fallbacks.jl:265 [inlined]
│      [8] columns
│        @ C:\Users\ahju\.julia\packages\Tables\NSGZI\src\fallbacks.jl:258 [inlined]
│      [9] DataFrames.DataFrame(x::ODBC.Cursor{false, false}; copycols::Nothing)
│        @ DataFrames C:\Users\ahju\.julia\packages\DataFrames\58MUJ\src\other\tables.jl:57
│     [10] DataFrame
│        @ C:\Users\ahju\.julia\packages\DataFrames\58MUJ\src\other\tables.jl:48 [inlined]
│     [11] |>(x::ODBC.Cursor{false, false}, f::Type{DataFrames.DataFrame})
│        @ Base .\operators.jl:917
│     [12] ¤¤¤MYCALLINGMETHOD¤¤¤(req::HTTP.Messages.Request)
│        @ ¤¤¤MyServerModule¤¤¤¤ c:\gitwork\¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤.jl:47

Minor edits sometimes also result in this error, which is not easier to understand.

┌ Error: ERROR: 
│   exception =
│ 
│    Stacktrace:
│      [1] error(s::String)
│        @ Base .\error.jl:35
│      [2] iterate(x::ODBC.Cursor{false, false}, st::Int64)
│        @ ODBC C:\Users\ahju\.julia\packages\ODBC\9VZTC\src\dbinterface.jl:398
│      [3] iterate
│        @ C:\Users\ahju\.julia\packages\ODBC\9VZTC\src\dbinterface.jl:387 [inlined]
│      [4] iterate
│        @ .\iterators.jl:206 [inlined]

ahjulstad avatar May 16 '24 06:05 ahjulstad