Skip to content

Commit d3ad39a

Browse files
committed
Add example to try and reproduce failure.
1 parent d179982 commit d3ad39a

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

examples/pgfault/config.ru

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require "pg"
4+
5+
run do |env|
6+
connection = PG.connect(dbname: "test")
7+
result = connection.exec("SELECT 1")
8+
Console.info(self, "Connection established to PostgreSQL database", result: result.to_a, connection: connection)
9+
connection.close
10+
11+
[200, {"content-type" => "text/plain"}, ["Hello, World!"]]
12+
end

examples/pgfault/falcon.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "pg"
4+
require "falcon/environment/rack"
5+
6+
connection = PG.connect(dbname: "test")
7+
result = connection.exec("SELECT 1")
8+
Console.info(self, "Connection established to PostgreSQL database", result: result.to_a, connection: connection)
9+
connection.close
10+
11+
service "hello.localhost" do
12+
include Falcon::Environment::Rack
13+
14+
endpoint do
15+
Async::HTTP::Endpoint.parse("http://hello.localhost:9292")
16+
end
17+
18+
preload "preload.rb"
19+
end

examples/pgfault/gems.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gem "pg"
6+
gem "falcon"

examples/pgfault/preload.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
require "pg"
3+
4+
connection = PG.connect(dbname: "test")
5+
result = connection.exec("SELECT 1")
6+
Console.info(self, "Connection established to PostgreSQL database", result: result.to_a, connection: connection)
7+
connection.close

examples/pgfault/readme.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# PG Segfault
2+
3+
On macOS, some usage of the Objective-C runtime can cause issues when forking. This can lead to a segmentation fault when using the `pg` gem with Falcon, but I've not been able to reproduce it thus far. If you encounter this, please report it: <https://github.com/socketry/falcon/issues/225>.
4+
5+
## Usage
6+
7+
### Postgres Setup
8+
9+
- Create a data directory.
10+
- `initdb -D data/`
11+
- `pg_ctl -D data/ start`
12+
- `createdb test`
13+
14+
(To stop, run `pg_ctl -D data/ stop`.)
15+
16+
### Run the server
17+
18+
```bash
19+
bundle exec falcon host
20+
```
21+
22+
Then visit <http://hello.localhost:9292>, e.g.
23+
24+
```bash
25+
curl http://hello.localhost:9292
26+
```
27+
28+
You should see "Hello, World!" in the response (and no errors/segfaults in the server logs).

0 commit comments

Comments
 (0)