open-vault/vault
Seth Bunce a6a437a1ce
fix deadlock on core state lock (#10456)
* fix race that can cause deadlock on core state lock

The bug is in the grabLockOrStop function. For specific concurrent
executions the grabLockOrStop function can return stopped=true when
the lock is still held. A comment in grabLockOrStop indicates that the
function is only used when the stateLock is held, but grabLockOrStop is
being used to acquire the stateLock. If there are concurrent goroutines
using grabLockOrStop then some concurrent executions result in
stopped=true being returned when the lock is acquired.

The fix is to add a lock and some state around which the parent and
child goroutine in the grabLockOrStop function can coordinate so that
the different concurrent executions can be handled.

This change includes a non-deterministic unit test which reliably
reproduces the problem before the fix.

* use rand instead of time for random test stopCh close

Using time.Now().UnixNano()%2 ends up being system dependent because
different operating systems and hardware have different clock
resolution. A lower resolution will return the same unix time for a
longer period of time.

It is better to avoid this issue by using a random number generator.
This change uses the rand package default random number generator. It's
generally good to avoid using the default random number generator,
because it creates extra lock contention. For a test it should be fine.
2020-12-10 06:50:11 -05:00
..
activity Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
cluster Port changes from enterprise lease fix (#10020) 2020-09-22 14:47:13 -07:00
external_tests Fix race with test that mutates KeyRotateGracePeriod: make the global be a Core field instead. (#10512) 2020-12-08 13:57:44 -05:00
quotas Backport last quota fix changes to OSS (#10335) 2020-11-06 09:46:31 -06:00
replication Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
seal Same seal migration oss (#10224) 2020-10-23 14:16:04 -04:00
acl.go Check nil parameter value when processing an ACL. 2019-04-26 15:57:00 -07:00
acl_test.go Update HCL dependency to fix ParseACLPolicy error on invalid syntax (#10156) 2020-11-30 09:17:33 -06:00
acl_util.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
activity_log.go Fix Racy Activity Log Tests (#10484) 2020-12-02 13:48:13 -07:00
activity_log_test.go Fix Racy Activity Log Tests (#10484) 2020-12-02 13:48:13 -07:00
activity_log_testing_util.go Fix Racy Activity Log Tests (#10484) 2020-12-02 13:48:13 -07:00
activity_log_util.go Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
audit.go Fix panic in handleAuditNonLogical if vault is sealed (#9310) (#10103) 2020-10-07 08:30:36 -04:00
audit_broker.go Allow plugins to submit audit requests/responses via extended SystemView (#6777) 2019-05-22 18:52:53 -04:00
audit_test.go audit: log invalid wrapping token request/response (#6541) 2019-07-05 14:15:14 -07:00
audited_headers.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
audited_headers_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
auth.go Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
auth_test.go reverting the tests to not use metrics when unnecessary (#10350) 2020-11-11 15:35:09 -08:00
barrier.go Test for overflow of the capacity value (#9317) 2020-06-25 11:22:13 -05:00
barrier_access.go Fix compile 2018-01-19 05:31:55 -05:00
barrier_aes_gcm.go Test for overflow of the capacity value (#9317) 2020-06-25 11:22:13 -05:00
barrier_aes_gcm_test.go Shamir seals now come in two varieties: legacy and new-style. (#7694) 2019-10-18 14:46:00 -04:00
barrier_test.go Shamir seals now come in two varieties: legacy and new-style. (#7694) 2019-10-18 14:46:00 -04:00
barrier_view.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
barrier_view_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
barrier_view_util.go The big one (#5346) 2018-09-17 23:03:00 -04:00
capabilities.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
capabilities_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
cluster.go Eliminate global that caused race tests to fail in ent with an internal config setting. (#9604) 2020-07-27 16:10:26 -04:00
cluster_test.go Fix flaky TestCluster_ForwardRequest tests. (#9973) 2020-09-16 15:31:06 -04:00
core.go Fix race with test that mutates KeyRotateGracePeriod: make the global be a Core field instead. (#10512) 2020-12-08 13:57:44 -05:00
core_metrics.go Port: Telemetry For Lease Expiration Times (#10375) 2020-11-13 10:26:58 -08:00
core_metrics_test.go Fix crash when KV store has a zero-length key. (#9881) 2020-09-02 17:43:44 -05:00
core_test.go Make manualStepDownCh a 1-buffered channel to ensure StepDown actually steps down in tests. (#9622) 2020-07-31 10:01:51 -04:00
core_util.go Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
cors.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
counters.go Move "counters" path to the logical system's local path list. (#10314) 2020-11-02 21:59:55 -06:00
counters_test.go Fix token counters test (#7867) 2019-11-12 13:33:28 -05:00
deadlock.go Add option to detect deadlocks in Core.stateLock using build tag `deadlock` (#8524) 2020-03-10 16:01:20 -04:00
dynamic_system_view.go Move sdk/helper/random -> helper/random (#9226) 2020-06-17 14:24:38 -06:00
dynamic_system_view_test.go Add user configurable password policies available to secret engines (#8637) 2020-05-27 12:28:00 -06:00
expiration.go Port: Telemetry For Lease Expiration Times (#10375) 2020-11-13 10:26:58 -08:00
expiration_integ_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
expiration_test.go Port: Telemetry For Lease Expiration Times (#10375) 2020-11-13 10:26:58 -08:00
expiration_util.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
generate_root.go Same seal migration oss (#10224) 2020-10-23 14:16:04 -04:00
generate_root_recovery.go Same seal migration oss (#10224) 2020-10-23 14:16:04 -04:00
generate_root_test.go Shamir seals now come in two varieties: legacy and new-style. (#7694) 2019-10-18 14:46:00 -04:00
ha.go fix deadlock on core state lock (#10456) 2020-12-10 06:50:11 -05:00
ha_test.go fix deadlock on core state lock (#10456) 2020-12-10 06:50:11 -05:00
identity_lookup.go Switch to go modules (#6585) 2019-04-13 03:44:06 -04:00
identity_lookup_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
identity_store.go Revert "Migrate internalshared out (#9727)" (#10141) 2020-10-13 16:38:21 -07:00
identity_store_aliases.go Prevent entity alias creation when entity is in different NS than mount (#943) (#6886) 2019-06-14 12:53:00 -04:00
identity_store_aliases_test.go Prevent entity alias creation when entity is in different NS than mount (#943) (#6886) 2019-06-14 12:53:00 -04:00
identity_store_entities.go VAULT-417: check expired context in entity API (#1445) (#9925) 2020-09-10 16:31:32 -06:00
identity_store_entities_test.go VAULT-417: check expired context in entity API (#1445) (#9925) 2020-09-10 16:31:32 -06:00
identity_store_group_aliases.go Update group alias handling to better protect against namespace differences 2019-06-18 16:43:30 -04:00
identity_store_group_aliases_test.go Update group alias handling to better protect against namespace differences 2019-06-18 16:43:30 -04:00
identity_store_groups.go Remove 512 entity limit for groups (#7317) 2019-08-14 13:47:11 -04:00
identity_store_groups_test.go Fix some tests 2019-06-17 17:02:34 -04:00
identity_store_oidc.go Fix identity token caching (#8412) 2020-02-26 15:56:19 -05:00
identity_store_oidc_test.go Run CI tests in docker instead of a machine. (#8948) 2020-09-15 10:01:26 -04:00
identity_store_oidc_util.go Fix identity token caching (#8412) 2020-02-26 15:56:19 -05:00
identity_store_schema.go Storage packer V1 updates (#6531) 2019-05-07 15:29:51 -04:00
identity_store_structs.go Fix identity case sensitivity loading in secondary cluster (#7327) 2019-09-30 10:27:25 -04:00
identity_store_test.go Fix a race caused by assignment to core.metricSink (#9560) 2020-07-22 13:52:10 -04:00
identity_store_upgrade.go Prevent entity alias creation when entity is in different NS than mount (#943) (#6886) 2019-06-14 12:53:00 -04:00
identity_store_util.go Entity and alias counts (#9262) 2020-06-23 19:45:59 -05:00
init.go Be consistent with how we report init status. (#10498) 2020-12-08 13:55:34 -05:00
init_test.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
keyring.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
keyring_test.go Spelling (#4119) 2018-03-20 14:54:10 -04:00
lock.go Add option to detect deadlocks in Core.stateLock using build tag `deadlock` (#8524) 2020-03-10 16:01:20 -04:00
logical_cubbyhole.go Reject requests read and write requests to cubbyhole with an empty path (#8971) 2020-05-11 14:15:36 -05:00
logical_cubbyhole_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
logical_passthrough.go Switch to go modules (#6585) 2019-04-13 03:44:06 -04:00
logical_passthrough_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
logical_raw.go Run go fmt (#7823) 2019-11-07 08:54:34 -08:00
logical_system.go Fix race with test that mutates KeyRotateGracePeriod: make the global be a Core field instead. (#10512) 2020-12-08 13:57:44 -05:00
logical_system_activity.go Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
logical_system_helpers.go Merge PR #10059: Port OSS changes from #1497 2020-10-01 15:15:20 -04:00
logical_system_integ_test.go Fix wrong err return value in plugin reload status command (#9348) 2020-06-30 13:33:30 -05:00
logical_system_paths.go Global Plugin Reload: OSS Changes Take II (#9347) 2020-06-30 10:26:52 -05:00
logical_system_pprof.go sys/pprof: fix pprof index description (#7564) 2019-10-03 17:02:41 -07:00
logical_system_quotas.go Backport last quota fix changes to OSS (#10335) 2020-11-06 09:46:31 -06:00
logical_system_raft.go OSS changes for enterprise automated snapshots (#10160) 2020-10-16 14:57:11 -04:00
logical_system_test.go Validate to/from parameters when remounting a backend (#9890) 2020-10-29 14:06:07 -04:00
mount.go Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
mount_test.go reverting the tests to not use metrics when unnecessary (#10350) 2020-11-11 15:35:09 -08:00
mount_util.go Port filtered paths changes back to OSS (#7741) 2019-10-27 13:30:38 -07:00
namespaces.go Backport some OSS changes (#10267) 2020-10-29 16:47:34 -07:00
plugin_catalog.go DBPW - Copy `newdbplugin` package to `dbplugin/v5` (#10151) 2020-10-15 13:20:12 -06:00
plugin_catalog_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
plugin_reload.go Fix wrong err return value in plugin reload status command (#9348) 2020-06-30 13:33:30 -05:00
policy.go Add identity templating helper to sdk/framework (#8088) 2020-01-06 10:16:52 -08:00
policy_store.go Add maximum amount of random entropy requested (#7144) 2019-07-24 18:22:23 -07:00
policy_store_test.go core/policy & core/token: Remove Dead Test Code (#7774) 2019-11-04 10:36:07 +01:00
policy_store_util.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
policy_test.go Fix hasMountPath for segment wildcard mounts; introduce priority order (#6532) 2019-04-10 17:46:17 -04:00
policy_util.go The big one (#5346) 2018-09-17 23:03:00 -04:00
raft.go Be consistent with how we report init status. (#10498) 2020-12-08 13:55:34 -05:00
rekey.go Fix panic in RekeyVerifyRestart (#9930) (#10099) 2020-10-07 11:06:17 -07:00
rekey_test.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
request_forwarding.go Eliminate global that caused race tests to fail in ent with an internal config setting. (#9604) 2020-07-27 16:10:26 -04:00
request_forwarding_rpc.go Revert global plugin reload commits (#9344) 2020-06-29 17:36:22 -05:00
request_forwarding_rpc_util.go The big one (#5346) 2018-09-17 23:03:00 -04:00
request_forwarding_service.pb.go Port changes from enterprise lease fix (#10020) 2020-09-22 14:47:13 -07:00
request_forwarding_service.proto Backport the pieces of the replication API changes (#9425) 2020-07-09 15:11:37 -07:00
request_handling.go auth: store period value on tokens created via login (#7885) 2020-10-26 16:25:56 -04:00
request_handling_test.go auth: store period value on tokens created via login (#7885) 2020-10-26 16:25:56 -04:00
request_handling_util.go Fix various read only storage errors 2019-07-05 18:13:49 -04:00
rollback.go Fixed a bunch of typos (#7146) 2019-07-18 21:10:15 -04:00
rollback_test.go Switch to go modules (#6585) 2019-04-13 03:44:06 -04:00
router.go Resource Quotas: Rate Limiting (#9330) 2020-06-26 17:13:16 -04:00
router_access.go The big one (#5346) 2018-09-17 23:03:00 -04:00
router_test.go Fix a deadlock if a panic happens during request handling (#6920) 2019-06-19 09:40:57 -04:00
router_testing.go AWS upgrade role entries (#7025) 2019-07-05 16:55:40 -07:00
seal.go Same seal migration oss (#10224) 2020-10-23 14:16:04 -04:00
seal_access.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
seal_autoseal.go Ensure that perf standbys can perform seal migrations. (#9690) 2020-08-10 08:35:57 -04:00
seal_autoseal_test.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
seal_test.go Shamir seals now come in two varieties: legacy and new-style. (#7694) 2019-10-18 14:46:00 -04:00
seal_testing.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
seal_testing_util.go Create configutil and move some common config and setup functions there (#8362) 2020-05-14 09:19:27 -04:00
sealunwrapper.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
sealunwrapper_test.go Migrate built in auto seal to go-kms-wrapping (#8118) 2020-01-10 20:39:52 -05:00
testing.go MySQL - Fix username generation length bug (#10433) 2020-12-01 15:24:51 -07:00
testing_util.go Port changes from enterprise lease fix (#10020) 2020-09-22 14:47:13 -07:00
token_store.go Only use entropy augmentation for root token creation [VAULT-670] (#10487) 2020-12-04 09:44:04 -08:00
token_store_test.go auth: store period value on tokens created via login (#7885) 2020-10-26 16:25:56 -04:00
token_store_util.go The big one (#5346) 2018-09-17 23:03:00 -04:00
ui.go UI - raft config and snapshotting (#7410) 2019-10-14 13:23:29 -05:00
ui_test.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00
util.go Removed unused methods 2017-01-03 12:51:35 -05:00
util_test.go Utility Enhancements 2016-04-05 20:32:59 -04:00
wrapping.go Revert "Migrate internalshared out (#9727)" (#10141) 2020-10-13 16:38:21 -07:00
wrapping_util.go Create sdk/ and api/ submodules (#6583) 2019-04-12 17:54:35 -04:00