Commit 7aa1751
authored
Fixes a bad bug in `riversharedtest.DBPool` in which while lazily
initializing a database pool, *we never actually set the database pool*,
so repeated invocations of `DBPool` would check for an existing pool
that would never exist and create a new one each time. This project
seems to be brute forcing its way by, but I was seeing Postgres
connection exhaustions in other projects.
Boiled down, the problem is that we had this:
dbPool, err := pgxpool.New(ctx, cmp.Or(
os.Getenv("TEST_DATABASE_URL"),
"postgres://localhost:5432/river_test",
))
When it should've been this:
var err error
dbPool, err = pgxpool.New(ctx, cmp.Or(
os.Getenv("TEST_DATABASE_URL"),
"postgres://localhost:5432/river_test",
))
Here, fix the problem, and go a step further to simplify the code
somewhat to use a `sync.Once` instead of mutex. The final product is
fewer lines of code, which will hopefully make a bug of this magnitude
easier to spot should it reoccur.
1 parent 83cb7a6 commit 7aa1751
2 files changed
Lines changed: 18 additions & 29 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
72 | 57 | | |
73 | 58 | | |
74 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
0 commit comments