Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on too many accesses to readonly #790

Closed
sam-s opened this issue Oct 12, 2018 · 1 comment
Closed

Segfault on too many accesses to readonly #790

sam-s opened this issue Oct 12, 2018 · 1 comment
Labels
Milestone

Comments

@sam-s
Copy link

sam-s commented Oct 12, 2018

I get

*** Error in `/.../bin/python3': free(): invalid pointer: 0x00007fb1336e7760 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81499)[0x7fb1325ee499]
/usr/lib64/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0xa69e)[0x7fb1333a902e]
/usr/lib64/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x1f2)[0x7fb1333aa822]
/usr/lib64/libpython3.6m.so.1.0(PyEval_EvalCode+0x3b)[0x7fb1333ab4cb]
/usr/lib64/libpython3.6m.so.1.0(+0x1d1eee)[0x7fb133430eee]
/usr/lib64/libpython3.6m.so.1.0(PyRun_FileExFlags+0xa4)[0x7fb1332e5ac2]
/usr/lib64/libpython3.6m.so.1.0(PyRun_SimpleFileExFlags+0x37a)[0x7fb1332e5e72]
/usr/lib64/libpython3.6m.so.1.0(Py_Main+0x88c)[0x7fb133437cfc]
/home/sds/.virtualenvs/algorisk/bin/python3(main+0x119)[0x400b19]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7fb13258f445]
/.../bin/python3[0x400ca1]

when I look at connection.readonly too many times.

The code is:

import psycopg2 as pg
from psycopg2 import extras

conn = pg.connect("...")

conn.set_session(autocommit=False, readonly=False)

with conn.cursor(name="test") as cu:
    cu.execute("select * from twits order by sid limit 11000;")
    for sid,rec in cu:
        if conn.readonly:
            raise ValueError("immutable")
        with conn.cursor() as cu1:
            cu1.execute("INSERT INTO twits (sid, status) VALUES (%s, %s) ON CONFLICT"
                        " (sid) DO UPDATE SET status = excluded.status;",
                        (sid, extras.Json(rec)))
        if cu.rownumber == cu.itersize:
            print(sid)

The table is created by

CREATE TABLE twits (
    sid bigint NOT NULL PRIMARY KEY,
    status jsonb NOT NULL
);

when I remove

        if conn.readonly:
            raise ValueError("immutable")

the problem disappears.
When I remove conn.set_session(autocommit=False, readonly=False), the crash turns into Fatal Python error: deallocating None.

PS. I check readonly because the connection is shared between threads.

@dvarrazzo
Copy link
Member

A simpler test to reproduce the crash:

for i in range(10000):
    conn.readonly

fix on the way, thank you for the report :)

@dvarrazzo dvarrazzo added this to the psycopg 2.7.6 milestone Oct 12, 2018
@dvarrazzo dvarrazzo added the bug label Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants