Commit 38c8d97
committed
fix(cmd): prevent test DB connection leak via app.Before config swap
TestShell_BeforeNode and TestShell_RunNode_WithBeforeNode were calling
app.Before(c) after pre-setting shell.Config with a txdb-wrapped config
via configtest.NewGeneralConfig. app.Before unconditionally ran
opts.New() → CoreDefaults() which set Database.DriverName back to pgx
and assigned the fresh config to s.Config, silently overwriting the
test's txdb config. BeforeNode → pg.NewLockedDB then opened real pgx
connections against the shared chainlink_test database, persisting
keystore state and leaking it to other tests (flaking Test_CSAKeyStore_E2E)
and eating slots from the server-wide max_connections budget (causing
the mass 25-minute chan-receive timeouts in CORE-2388).
Three changes:
1. core/cmd/app.go — guard the config creation in app.Before so a
pre-set s.Config is preserved. Defense-in-depth: any future test
that sets its own config and goes through app.Before is protected
from the same silent swap.
2. core/cmd/shell_local.go — nil-guard CloseLogger in afterNode. Tests
that call BeforeNode directly (without app.Before) never set it.
app.After already has this nil check; afterNode was missing it.
3. core/cmd/shell_local_test.go — remove the unnecessary app.Before(c)
calls from the two affected tests. BeforeNode only needs Config and
Logger, both already set directly; other tests in the same file
already build the shell this way. Also drop the incorrect_password
subtests — they were load-bearing on the leak (the correct_password
subtest would persist a CSA key to the shared DB, which the
incorrect_password subtest would then fail to decrypt, producing
the expected error). The wrong-password-against-populated-keyring
invariant is already covered at the correct layer by
TestMasterKeystore_Unlock_Save/won't_load_a_saved_keyRing_if_the_password_is_incorrect
in core/services/keystore. Testing it through the CLI would require
cross-connection state sharing that chainlink's txdb path does not
support: chainlink-common/pkg/sqlutil/pg/pg.go:69 generates a fresh
UUID DSN per pg.NewConnection call, isolating every pool into its
own transaction.
Refs: CORE-2388, CORE-2370
Supersedes: #215041 parent d62edd5 commit 38c8d97
3 files changed
Lines changed: 43 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | 83 | | |
89 | 84 | | |
90 | 85 | | |
91 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
| |||
122 | 128 | | |
123 | 129 | | |
124 | 130 | | |
125 | | - | |
| 131 | + | |
126 | 132 | | |
127 | 133 | | |
128 | 134 | | |
129 | | - | |
| 135 | + | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1241 | 1241 | | |
1242 | 1242 | | |
1243 | 1243 | | |
1244 | | - | |
1245 | | - | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
1246 | 1248 | | |
1247 | 1249 | | |
1248 | 1250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
510 | 516 | | |
511 | 517 | | |
512 | 518 | | |
513 | 519 | | |
514 | 520 | | |
515 | 521 | | |
516 | | - | |
517 | 522 | | |
518 | 523 | | |
519 | 524 | | |
| |||
543 | 548 | | |
544 | 549 | | |
545 | 550 | | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
555 | 556 | | |
556 | 557 | | |
557 | 558 | | |
| |||
577 | 578 | | |
578 | 579 | | |
579 | 580 | | |
| 581 | + | |
| 582 | + | |
580 | 583 | | |
581 | 584 | | |
582 | 585 | | |
583 | 586 | | |
584 | 587 | | |
585 | 588 | | |
586 | | - | |
587 | 589 | | |
588 | 590 | | |
589 | 591 | | |
| |||
641 | 643 | | |
642 | 644 | | |
643 | 645 | | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
650 | 653 | | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
657 | 659 | | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | 660 | | |
668 | 661 | | |
669 | 662 | | |
| |||
0 commit comments