Skip to content

on_disconnect.sql ? #373

Open
Open
@lyderic

Description

@lyderic

Introduction

I am trying to use functions in SQLite and I found the define SQLite extension from the reputable sqlean set.

In the documentation, they say: "Scalar functions are compiled into prepared statements. SQLite requires these statements to be freed before the connection is closed. Unfortunately, there is no way to free them automatically. Therefore, always execute define_free() before disconnecting".

When I call define_free() at the end of a .sql page though, sqlpage crashes after a page refresh.

To Reproduce

  1. Download the sqlean zip file for your OS from the sqlean release page and uncompress it somewhere, e.g. I am on Linux and I chose /usr/local/lib/sqlext
$ wget https://github.com/nalgeon/sqlean/releases/download/0.23.0/sqlean-linux-x86.zip
$ sudo mkdir -p /usr/local/lib/sqlext
$ sudo unzip sqlean-linux-x86.zip define.so -d /usr/local/lib/sqlext
  1. Create a sqlpage project with the following configuration file:

sqlpage/sqlpage.yaml

port: 4004
database_url: "sqlite://:memory:"
sqlite_extensions:
  - "/usr/local/lib/sqlext/define.so"
  1. Create this migration script to define a function:

sqlpage/migrations/01_functions.sql

SELECT define('eurof', 'format(''%,.2f €'', :n)');
  1. Create a basic home page:

index.sql

SELECT 'text' AS component, eurof(3000.3892) AS contents;
SELECT define_free();

Actual behavior

Open a browser tab to http://localhost:4004. The page loads normally and the expected value is displayed, as formatted by the eurof function, i.e. 3,000.39 €. So far, so good.

However, if the page is refreshed (hit Ctrl-R once or twice), sqlpage crashes and doesn't display anything else than:

Segmentation fault (core dumped)

Expected behavior

I expected no crash, of course. It is subtle, as one has to reload the page to make the sqlpage service crash.

It doesn't look like a bug in sqlean (I can't reproduce it when using the sqlite3 interpreter).

Maybe I don't put the call to define_free() in the right place. If this is the case, where shall I put it? In other words, as I am supposed to call define_free() before disconnecting, when does sqlpage "disconnect" from sqlite?

Maybe the call to define_free() is not necessary at all! If I comment is out, there is no crash: in this case though, is this not a potential memory leak?

If it helps, I attach a log of the the full interaction. I produced it with the following command:

RUST_LOG=sqlpage=debug sqlpage > log.txt 2>&1

Version information

  • OS: Arch
  • Database: SQLite
  • SQLPage: 0.22.0
  • sqlean: 0.23.0

Additional context

I am not sure this is a bug, or me missing something. I apologize in advance if this is misleading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions