Kitura / Swift-Kuery-ORM

An ORM for Swift, built on Codable
Apache License 2.0
212 stars 30 forks source link

Possible data corruption issue under stress #71

Closed djones6 closed 5 years ago

djones6 commented 6 years ago

Context and Description

I think there may be a concurrency issue with Kuery-ORM when subjected to stress which causes infrequent errors, but looks like it could potentially cause data corruption.

I am using this work-in-progress branch of my TechEmpower implementation for Kitura, compiled in release mode, and driven with the following command:

wrk -c128 -t4 -d30s http://localhost:8080/db

Client output:

Running 30s test @ http://localhost:8080/db
  4 threads and 128 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    27.07ms   50.19ms 388.46ms   88.90%
    Req/Sec     2.94k   250.29     3.78k    70.75%
  351630 requests in 30.02s, 68.00MB read
  Socket errors: connect 0, read 7, write 0, timeout 0
  Non-2xx or 3xx responses: 6
Requests/sec:  11711.99
Transfer/sec:      2.26MB

...the Non-2xx or 3xx responses line indicates the number of failed requests during this period.

The corresponding output from the Kitura process:

bananas:latest djones6$ .build/release/TechEmpowerPostgresORM
2018-11-01 15:58:56.243 TechEmpowerPostgresORM[19240:215117] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon or value in dictionary on line 1. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolonOrValue to debug.
[2018-11-01T15:58:56.329Z] [INFO] [HTTPServer.swift:195 listen(on:)] Listening on port 8080
[2018-11-01T15:59:16.245Z] [ERROR] [main.swift:65 TechEmpowerPostgresORM] 706 : Query execution error:
ERROR:  invalid byte sequence for encoding "UTF8": 0x90
 For query: SELECT * FROM "world" WHERE "world"."id" = $1
[2018-11-01T16:14:14.680Z] [ERROR] [main.swift:65 TechEmpowerPostgresORM] 706 : Query execution error:
ERROR:  invalid input syntax for integer: ""
 For query: SELECT * FROM "world" WHERE "world"."id" = $1
[2018-11-01T16:14:15.810Z] [ERROR] [main.swift:65 TechEmpowerPostgresORM] 706 : Query execution error:
ERROR:  invalid input syntax for integer: "ld".""
 For query: SELECT * FROM "world" WHERE "world"."id" = $1
[2018-11-01T16:14:18.968Z] [ERROR] [main.swift:65 TechEmpowerPostgresORM] 706 : Query execution error:
ERROR:  invalid input syntax for integer: ""
 For query: SELECT * FROM "world" WHERE "world"."id" = $1
[2018-11-01T16:16:24.992Z] [ERROR] [main.swift:65 TechEmpowerPostgresORM] 706 : Query execution error:
ERROR:  invalid byte sequence for encoding "UTF8": 0xc9 0xcf
 For query: SELECT * FROM "world" WHERE "world"."id" = $1
[2018-11-01T16:16:25.543Z] [ERROR] [main.swift:65 TechEmpowerPostgresORM] 706 : Query execution error:
ERROR:  invalid byte sequence for encoding "UTF8": 0xf9
 For query: SELECT * FROM "world" WHERE "world"."id" = $1

The same benchmark driven by the TechEmpowerPostgres executable (which uses Kuery directly and does not involve the ORM) runs without such errors.

Also, running with fewer concurrent connections (eg. 20) seems to prevent the errors from occurring.

Environment Details

macOS 10.13.6 High Sierra, Swift 4.2.1 (Xcode 10.1), compiled in release mode. Running against a local PostgreSQL database.

Steps to Reproduce

1) ... 2) ...

Expected vs. Actual Behaviour

djones6 commented 6 years ago

@kilnerm FYI.

djones6 commented 5 years ago

Interestingly, using the issue_adopt_async changes, I no longer see these errors.

kilnerm commented 5 years ago

@djones6 Does this need further investigation or can we close it based on the issue not occurring with Kuery 3.0?