Code Monkey home page Code Monkey logo

Comments (6)

megri avatar megri commented on August 25, 2024

I managed to reproduce the bug. Postgres reports the error as

postgres_1  | 2020-04-21 18:40:55.456 UTC [27] ERROR:  insert or update on table "foo" violates foreign key constraint "foo_bar_id_fkey"

https://github.com/megri/skunk-bugreport

from skunk.

megri avatar megri commented on August 25, 2024

I rewrote my bug report with natchez-log but traces are never logged as the process deadlocks before it comes that far. I also noticed that deadlock seemingly occurs for any INSERT queries with RETURNING, that fails for at least foreign key violation error.

Adding readTimeout/writeTimeout arguments to the session pool does not prevent deadlock.

from skunk.

megri avatar megri commented on August 25, 2024

Log from start to the point of deadlock

→ StartupMessage(postgres,postgres)
 ← AuthenticationOk
 ← ParameterStatus(application_name,)
 ← ParameterStatus(client_encoding,UTF8)
 ← ParameterStatus(DateStyle,ISO, MDY)
 ← ParameterStatus(integer_datetimes,on)
 ← ParameterStatus(IntervalStyle,iso_8601)
 ← ParameterStatus(is_superuser,on)
 ← ParameterStatus(server_encoding,UTF8)
 ← ParameterStatus(server_version,11.7)
 ← ParameterStatus(session_authorization,postgres)
 ← ParameterStatus(standard_conforming_strings,on)
 ← ParameterStatus(TimeZone,UTC)
 ← BackendKeyData(161,1923859743)
 ← ReadyForQuery(Idle)
 → Parse(statement_1,INSERT INTO "foo" ("bar_id") VALUES ($1) RETURNING *,List(20))
 → Flush
 ← ParseComplete
 → Describe(S, statement_1)
 → Flush
 ← ParameterDescription(List(20))
 ← RowDescription(Field(id, 20); Field(bar_id, 20))
 → Bind(portal_2,statement_1,List(Some(42)))
 → Flush
 ← BindComplete
 → Execute(portal_2,2)
 → Flush
 ← ErrorResponse(s -> public, n -> foo_bar_id_fkey, t -> foo, F -> ri_triggers.c, M -> insert or update on table "foo" violates foreign key constraint "foo_bar_id_fkey", V -> ERROR, L -> 2772, C -> 23503, R -> ri_ReportViolation, D -> Key (bar_id)=(42) is not present in table "bar"., S -> ERROR
 → Close(P,portal_2)
 → Flush

from skunk.

megri avatar megri commented on August 25, 2024

It seems plausible that the code deadlocks @ https://github.com/tpolecat/skunk/blob/29741a10acba5f4dff51b5c66d007065b313ad11/modules/core/src/main/scala/net/protocol/Close.scala#L40, expecting a CloseComplete that never comes.

from skunk.

megri avatar megri commented on August 25, 2024

From https://www.postgresql.org/docs/11/protocol-flow.html (emphasis mine):

The Close message closes an existing prepared statement or portal and releases resources. It is not an error to issue Close against a nonexistent statement or portal name. The response is normally CloseComplete, but could be ErrorResponse if some difficulty is encountered while releasing resources. Note that closing a prepared statement implicitly closes any open portals that were constructed from that statement.

Could this be the cause?

from skunk.

megri avatar megri commented on August 25, 2024

As it seems the fix resolved the issue for me I'll close it now!

from skunk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.