Test project to reproduce a lockup in Vapor

Overview

Test project to reproduce a lockup in Vapor

The issue was first observed when backing up the SPI database during operation. Running pg_dump would cause the site to return 500s.

This project reproduces the issue with the default Vapor app template and its Todo table.

The Makefile contains some basic commands we'll use to trigger the lockup.

Prerequisites

Installation of Rester either via

git clone https://github.com/finestructure/rester
cd rester
swift build -c release

or

brew install mint
mint install finestructure/rester

Triggering the error

It should suffice to run three processes in three terminal windows:

make db-up migrate
make run

to bring up the server

make get

to start a request loop that continuously fetches batches of 50 todos.

make post & ; make post & ; make post & ; make post & ; make post & ; make post & ; make post & ; make post & ; make post & ; make post & ; make post & ; make post &

to start a barrage of post requests adding new Todos. Depending on the machine the error may require additional or fewer make post jobs.

The error should manifest itself by first one and then the other terminals running into timeouts:

🎬  todos started ...

❌  Error: request timed out: todos
make: *** [get] Error 1

At this point everything comes to a standstill and even opening the static page http://localhost:8080/ in a browser (which should simply display "It works!" without any db access) hangs and does not load.

If forcing the error proves to be problematic, running

make dump

to pg_dump the database in parallel to the read and write jobs should do the trick.

You might also like...
A small project to understand the basic concepts of Vapor with Fluent.

Getting started with Vapor A small project to understand the basic concepts of Vapor with Fluent. Run Command on Terminal To create a new project, the

🗃 Powerful and easy to use Swift Query Builder for Vapor 3.
🗃 Powerful and easy to use Swift Query Builder for Vapor 3.

⚠️ This lib is DEPRECATED ⚠️ please use SwifQL with Bridges Quick Intro struct PublicUser: Codable { var name: String var petName: String

A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.

Puffery An iOS App written in SwiftUI to send push notifications fueled by Siri Shortcuts. You can follow other's channels and directly receive update

Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.
Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.

Vapor Leaf Extension Update: The Vapor Leaf Extension is now meant to be used with the Xcode Plugin I designed to provide Xcode language support for t

Swift Bot with Vapor for Telegram Bot Api

Telegram Vapor Bot Please support Swift Telegram Vapor Bot Lib development by giving a ⭐️ Telegram Bot based on Swift Vapor. Swift Server Side Communi

A template Vapor app with nginx frontend.
A template Vapor app with nginx frontend.

This is an example Vapor app. It contains the app itself, as well as surrounding components (Postgres database, nginx frontend for providing secure connection), all runnable out of the box with docker compose. It is a good starting point for Vapor development of an API server which you could access from macOS and iOS clients.

VaporDocC provides middleware for use with Vapor.

VaporDocC provides middleware for use with Vapor. To initialise the middleware pass in the path to your .doccarchive, e.g.:

 🪶 Feather is a modern Swift-based content management system powered by Vapor 4.
🪶 Feather is a modern Swift-based content management system powered by Vapor 4.

Feather CMS 🪶 🪶 Feather is a modern Swift-based content management system powered by Vapor 4. 💬 Click to join the chat on Discord. Requirements To

A sample application showcasing Vapor 4 connecting to an Oracle database using SwiftOracle package.

vapor-oracle A sample application showcasing Vapor 4 connecting to an Oracle database using SwiftOracle package. In this Vapor application, we create

A dockerized microservice written in Swift using Vapor.

price-calculation-service-swift This is an example project for a university project. It uses Vapor to serve a microservice written in Swift. The point

Auto Migration generation for Vapor projects

AutoMigrator A package that generates version based migrations from Fluent.Model types. The project will check your database scheme and understand whe

A movie api created using Vapor, Fluent (ORM) and Postgres

A movie api created using Vapor, Fluent (ORM) and Postgres

Demo Vapor TIL App

Demo Vapor TIL App

A template to get vapor working on Google App Engine

Swift Vapor App Engine This is a template to get vapor working on Google App Engine. Really all that's special is that it has a Dockerfile (included w

Swift package for adding API Key requirement to vapor backends.

APIKeyMiddleware Swift package for adding API Key requirement to vapor backends. Features ✅ Supports an array of keys ✅ Supports overriding thrown err

OpenAPI specification generator for Vapor based Swift projects.

VaporToOpenAPI VaporToOpenAPI is a Swift library which can generate output compatible with OpenAPI version 3.0.1 from Vapor code. You can use generate

PushDispatcher-vapor - Simple Api to dispatch push to APNS with p8 file

PushDispatcher - Vapor The purpose of this application is to facilitate the test

A slim implementation of a websocket server using Swift and Vapor 4.0.

Swift Websocket Server Example using Vapor 4.0 This project includes a minimum working example for a websocket server written in Swift. To interact wi

Comments
  • New details

    New details

    Interesting new details regarding the lockup error.

    I wanted to understand if the problem is in Vapor, Fluent, or perhaps NIO so I re-implemented the little example with Hummingbird and its Fluent module: https://github.com/finestructure/hummingbird-lockup-repro

    I ported the example with the same API and ran make post, which sends a post request with Rester. I got a crash in the server:

    Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range
    make: *** [run] Trace/BPT trap: 5
    

    The index out of range is happening in the second precondition on line 77 in HBParser.swift:

        init(_ parser: HBParser, range: Range<Int>) {
            self.buffer = parser.buffer
            self.index = range.startIndex
            self.range = range
    
            precondition(range.startIndex >= 0 && range.endIndex <= self.buffer.endIndex)
            precondition(self.buffer[range.startIndex] & 0xC0 != 0x80) // check we arent in the middle of a UTF8 character
        }
    
    (lldb) po range
    ▿ Range(7..<7)
      - lowerBound : 7
      - upperBound : 7
    
    (lldb) po buffer
    ▿ 7 elements
      - 0 : 47
      - 1 : 116
      - 2 : 111
      - 3 : 100
      - 4 : 111
      - 5 : 115
      - 6 : 63
    

    , which is /todos?. Not entirely sure where the ? is coming from, it's not in the initial request, but let's leave that aside for now.

    Because I couldn't believe Hummingbird would crash on such a simple example I tried to run a post request with the shipping example todos-fluent via Rester and ... it crashed in the same place!

    However, the todos-fluent example comes with a Paw file and running the post request from there ... works!

    I inspected the difference in the requests between Paw and Rester and started eliminating some of the minor differences but that made no change.

    Instead of trying to debug this I swapped Rester out of the repro steps in favour of curl. Now the Hummingbird example worked, and the lock-up was not reproducible. Apart from the weird crash when using Rester, Hummingbird performed just fine, processed all posts, gets, and even dumps in a loop.

    On a hunch, I went back to the Vapor repro example and swapped out Rester for curl and ... the lockup does not reproduce anymore. Switching back to Rester does lock it up.

    So it appears that the way Rester is making requests

    • crashes Hummingbird
    • causes Vapor to lock up

    Now Rester shouldn't be doing anything esoteric: it's a Swift tool triggering web requests using URLSession.dataTask. Did I (having written Rester) somehow manage to create a Swift server nuke?

    But even if the problem lies with my implementation in Rester, something similar must be happening in a Vapor server, because remember: we can bring the Swift Package Index server down when running web requests via Safari and dumping the Postgres database via pg_dump.

    This example using Rester is purely a local way to reproduce the error.

    It's unclear to me what exactly is going on but it certainly looks like there's a common root problem that affects both Vapor and Hummingbird - but in different ways.

    Or maybe I'm just holding it very wrong, which is entirely possible 🤣

    FYI @fabianfett @adam-fowler

    opened by finestructure 38
Owner
Sven A. Schmidt
Physicist & techie, independent software developer. Creator of the Swift Package Index.
Sven A. Schmidt
A dockerized microservice written in Swift using Vapor.

price-calculation-service-swift This is an example project for a university project. It uses Vapor to serve a microservice written in Swift. The point

Fabian Geistert 1 Aug 23, 2022
Auto Migration generation for Vapor projects

AutoMigrator A package that generates version based migrations from Fluent.Model types. The project will check your database scheme and understand whe

Mats Eikeland Mollestad 9 Jun 18, 2022
A template to get vapor working on Google App Engine

Swift Vapor App Engine This is a template to get vapor working on Google App Engine. Really all that's special is that it has a Dockerfile (included w

Michael 2 Oct 10, 2022
Vapor-telemetrydeck - Vapor client for posting signals to TelemetryDeck, a privacy-conscious analytics service for apps and websites

Vapor-telemetrydeck - Vapor client for posting signals to TelemetryDeck, a privacy-conscious analytics service for apps and websites

Sidetrack 7 Jun 16, 2022
Sample project to reproduce Xcode 13 indexing problems

Xcode 13 indexing regression for Swift static libraries Summary: Currently if you have a project that links a pre-compiled Swift static library (with

André Alves 13 Nov 3, 2022
Deck is a library that provides a UI to reproduce stacked cards for SwiftUI.

Deck Deck is a library that provides a UI to reproduce stacked cards for SwiftUI. RPReplay_Final1624531727.mov Usage struct Card: View { var data

1amageek 21 Dec 14, 2022
Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.

ActionSheetPicker-3.0 Important update Now I fixed most of the things and merge PR' (thanks to ). I did much work to support this library from iOS 5.

Petr Korolev 3.4k Dec 21, 2022
Steps and files needed to reproduce a CSP bug in Safari Web Extensions

CSP Safari bug repro There appears to be a discrepancy between how Safari handles CSP policies for extension pages compared to how other browsers do s

Brian Birtles 0 Nov 6, 2021
Test-To-Do-List - Test To Do List with core data

test-To-Do-List This is my first pet project with core data Launch screen Main s

Artem 0 Feb 26, 2022
Kfm-ios-test - Test online for iOS Developer position in Kimia Farma or PT. Buana Varia Komputama

kfm-ios-test Kimia Farma Mobile iOS Test Test online for iOS Developer position

Erwindo Sianipar 3 Feb 23, 2022