vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
322 stars 75 forks source link

1.18 crashes on Linux #405

Closed grahamburgsma closed 1 year ago

grahamburgsma commented 1 year ago

Describe the bug

Upgrading to 1.18 (and no other changes) crashes Vapor app when running on Linux server, works fine on Mac.

Crash logs aren't very helpful in diagnosing the issue, but maybe there's a clue you can see.

[ DEBUG ] CREATE TABLE IF NOT EXISTS "_fluent_migrations"("id" UUID PRIMARY KEY, "name" TEXT NOT NULL, "batch" BIGINT NOT NULL, "created_at" TIMESTAMPTZ, "updated_at" TIMESTAMPTZ, CONSTRAINT "uq:_fluent_migrations.name" UNIQUE ("name")) [[]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
[ DEBUG ] query read _fluent_migrations limits=[count(1)] [database-id: psql] (FluentKit/QueryBuilder.swift:293)
[ DEBUG ] SELECT "_fluent_migrations"."id" AS "_fluent_migrations_id", "_fluent_migrations"."name" AS "_fluent_migrations_name", "_fluent_migrations"."batch" AS "_fluent_migrations_batch", "_fluent_migrations"."created_at" AS "_fluent_migrations_created_at", "_fluent_migrations"."updated_at" AS "_fluent_migrations_updated_at" FROM "_fluent_migrations" ORDER BY "_fluent_migrations"."batch" DESC LIMIT 1 [[]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
[ DEBUG ] query read _fluent_migrations [database-id: psql] (FluentKit/QueryBuilder.swift:293)
[ DEBUG ] SELECT "_fluent_migrations"."id" AS "_fluent_migrations_id", "_fluent_migrations"."name" AS "_fluent_migrations_name", "_fluent_migrations"."batch" AS "_fluent_migrations_batch", "_fluent_migrations"."created_at" AS "_fluent_migrations_created_at", "_fluent_migrations"."updated_at" AS "_fluent_migrations_updated_at" FROM "_fluent_migrations" [[]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
Received signal 11. Backtrace:
0xaaaae8e41b77, Backtrace.(printBacktrace in _B82A8C0ED7C904841114FDF244F9E58E)(signal: Swift.Int32) -> () at /build/.build/checkouts/swift-backtrace/Sources/Backtrace/Backtrace.swift:66
0xaaaae8e41d27, closure #1 (Swift.Int32) -> () in static Backtrace.Backtrace.install(signals: Swift.Array<Swift.Int32>) -> () at /build/.build/checkouts/swift-backtrace/Sources/Backtrace/Backtrace.swift:80
0xaaaae8e41d27, @objc closure #1 (Swift.Int32) -> () in static Backtrace.Backtrace.install(signals: Swift.Array<Swift.Int32>) -> () at /build/<compiler-generated>:79
0xffff875ab667
0xffff864e1b38
0xffff864d895b
0xffff862b6f7f
Segmentation fault (core dumped)

Environment

Docker image swift:5.8-focal-slim running on AWS ECS Fargate.

MahdiBM commented 1 year ago

What is the Vapor version that the build process of your app would pull? This is likely a vapor issue which we've had report of in the Server, after a new release for more Sendable-compatibility (https://github.com/vapor/vapor/releases/tag/4.80.0)

MahdiBM commented 1 year ago

To be fair it looks more like a Swift issue than Vapor, but from a user standpoint those are pretty much the same i guess.

Anyway this issue should be moved to the Vapor repo, pretty sure it isn't related to PostgresNIO 🙂

fabianfett commented 1 year ago

@grahamburgsma Which Swift version do you use? Do you use static linking? Can you reduce your crasher?

grahamburgsma commented 1 year ago

@MahdiBM The original report was with 4.80. Just tried with 4.79 and the server started, but had this error log (below), but then a minute later crashed with the same error as before.

@fabianfett Swift version 5.8.1. I don't specify when running, so I'm guessing no static linking.

[ DEBUG ] Channel error caught. [database-id: psql, psql_connection_id: 2, psql_error: handshakeFailed(NIOSSL.BoringSSLError.sslError([Error: 268435593 error:10000089:SSL routines:OPENSSL_internal:DECODE_ERROR at /build/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/ssl_x509.cc:303, Error: 268435593 error:10000089:SSL routines:OPENSSL_internal:DECODE_ERROR at /build/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/handshake_client.cc:949]))] (PostgresNIO/PostgresChannelHandler.swift:104)
[ DEBUG ] Cleaning up and closing connection. [database-id: psql, psql_connection_id: 2, psql_error: PSQLError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use `String(reflecting: error)`.] (PostgresNIO/PostgresChannelHandler.swift:566)
[ ERROR ] Opening new connection for pool failed: PSQLError(code: connectionError, underlying: NIOSSL.NIOSSLError.handshakeFailed(NIOSSL.BoringSSLError.sslError([Error: 268435593 error:10000089:SSL routines:OPENSSL_internal:DECODE_ERROR at /build/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/ssl_x509.cc:303, Error: 268435593 error:10000089:SSL routines:OPENSSL_internal:DECODE_ERROR at /build/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/handshake_client.cc:949]))) [database-id: psql] (AsyncKit/EventLoopConnectionPool.swift:228)
fabianfett commented 1 year ago

@grahamburgsma Which command do you use to compile?

grahamburgsma commented 1 year ago

Which command do you use to compile?

Build with Docker:

FROM swift:5.8-focal
RUN swift build -c release
fabianfett commented 1 year ago

Does it repro with 5.8.1 explicitly as well?

FROM swift:5.8.1-focal
RUN swift build -c release
fabianfett commented 1 year ago

Okay, I can repro a crash in 5.8.1.

fabianfett commented 1 year ago

@grahamburgsma this should be fixed with 1.18.1. Can you please validate the fix on your side for me?

grahamburgsma commented 1 year ago

Should be fixed with 1.18.1. Can you please validate the fix on your side for me?

@fabianfett 1.18.1 does indeed fix it, thank you! 🙌