Repository navigation
Fix/ocisdev 1433 - #748
Fix/ocisdev 1433#748
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
kobergj
left a comment
There was a problem hiding this comment.
Reviewed the public-share manager changes (d4f339c + 95d977d). The direction is right - taking the read-modify-write out of GetPublicShare / GetPublicShareByToken / ListPublicShares, dropping the manager lock before the gateway Stat fan-out, and deleting the signal.Notify(SIGHUP, SIGINT, SIGQUIT) janitor hack (which was suppressing the default signal disposition process-wide) are all clear improvements. Wiring Close through rgrpc.cleanupServices and passing the request context into init() are good too.
One blocking issue in cs3.Write (cache/mtime inconsistency that defeats IfUnmodifiedSince), plus a few smaller things inline.
One process note: no changelog entry for these two commits, although the other commits in this PR each add one - and this change is user-visible (expired shares are no longer purged on access, janitor cadence changed, new shutdown semantics).
e2e5895 to
6760373
Compare
…n a public shares
The cs3 metadata storage authenticates as a system user before every operation, and that Authenticate call carried no deadline. A gateway that accepted the connection but never answered it - because it was itself waiting on a stalled storage provider - parked the calling goroutine for the lifetime of the process, with no log output at all. The call now runs on its own bounded context and logs a warning when the deadline is exhausted. The context returned to the caller deliberately keeps no deadline: callers run their own RPC on it after getAuthContext returns. Adds the first tests for this package, including one that reproduces the unbounded wait against an in-process gateway that never answers. Co-Authored-By: Claude Opus 5 <[email protected]>
The grpc client connections of the pool were created without keepalive parameters, so a peer that stopped answering on an established connection - a black-holed node, a wedged process - was indistinguishable from a peer that was merely slow, and a request without a deadline waited for the lifetime of the process. The clients now ping the peer while a request is in flight and fail the requests on a connection that does not answer, tunable with GRPC_CLIENT_KEEPALIVE_TIME and GRPC_CLIENT_KEEPALIVE_TIMEOUT. The servers got the matching enforcement policy so they accept those pings. GRPC_MAX_CONNECTION_AGE is removed along with it. It closed healthy connections on a timer, never ended a request that was already in flight because the grace period was left at infinity, and fell back to doing nothing at all whenever its value had no unit suffix. Co-Authored-By: Claude Opus 5 <[email protected]>
…sist label to the manager.
6760373 to
3755f25
Compare
dad8d79 to
0bec0b9
Compare
kobergj
left a comment
There was a problem hiding this comment.
Re-checked the branch at e6768c6c against my review from 9/25. All nine points are addressed or answered, several more thoroughly than asked:
- the
cs3.Writemtime/content inconsistency is fixed by invalidating instead of syncing, andcs3_write_test.gopins both interleavings - the invisible share and the dropped share - the unchecked type assertions are gone from the whole file, not just the janitor, behind
dbEntryString Copymoved to the write paths andReadis documented read-only, withTestReadDoesNotCopyTheDatabasebounding the allocations- the three flaky wall-clock assertions are now a concurrency counter and two channel handshakes
- changelog added
On the janitor holding the write lock across Read + Write: agreed, leave it. IfUnmodifiedSince would in principle catch a lost update, but without a retry the run would just fail, so the conservative version is the right call.
The black-hole proxy test in keepalive_test.go is a good addition - it pins the failure mode rather than the fix.
Three non-blocking comments below, plus one process note: the commit that adds disable_propfind_public_link_resolution has no changelog entry. That is the only one I would do before merge; the rest are fine as follow-ups.
| // Invalidate the cache to minimize the risk of inconsistency. | ||
| p.db.mtime = time.Time{} | ||
| p.db.publicShares = persistence.PublicShares{} |
There was a problem hiding this comment.
p.db.mtime does double duty - "is my cached content current" and "what did the remote look like when I last saw it" - and clearing it here serves the first while dropping the second.
If the next Read takes the NotFound branch above (line 103) it returns early without ever setting mtime, so the Write that follows uploads with IfUnmodifiedSince zero, which metadata.CS3.Upload reads as "no precondition at all" (pkg/storage/utils/metadata/cs3.go:218). The content it uploads is derived from the emptied cache, so a CreatePublicShare in that state replaces the whole publicshares.json with that single share. Before this change Write left mtime alone, so even on that branch the next upload still carried a real precondition and would have failed instead.
Not blocking: it needs Stat to report NotFound while Upload still succeeds, and if the file was genuinely deleted there is nothing left to lose. But the two concerns separate cleanly, and then the invariant holds without depending on that:
// Invalidate the cache so the next Read refetches, without forgetting the
// mtime the next Write needs for its IfUnmodifiedSince precondition.
p.db.stale = truewith a stale bool on type db, Read refetching on p.db.stale || utils.TSToTime(info.Mtime).After(p.db.mtime) and clearing it after a successful refill. The NotFound branch then also keeps returning the last known content instead of nothing.
| if share, ok := dbEntryString(v, shareField); ok { | ||
| if err := utils.UnmarshalJSONToProtoV1([]byte(share), &local.PublicShare); err != nil { | ||
| log.Error().Err(err).Msg("error unmarshalling share") | ||
| } | ||
| } else { | ||
| log.Error().Msg("error reading share entry: missing or invalid \"share\" field") | ||
| } |
There was a problem hiding this comment.
Every other call site skips an entry it cannot read; here it logs and still pushes &local. Load on the receiving side keys on ps.PublicShare.Id.GetOpaqueId() (line 299), which is "" for a zero-valued share, so one corrupt source entry becomes a junk entry under the empty key in the target - and each further bad entry overwrites it.
Migration-only, so low severity, but this is the one place the new helper tolerates an unreadable entry instead of dropping it:
share, ok := dbEntryString(v, shareField)
if !ok {
log.Error().Msg("error reading share entry: missing or invalid \"share\" field")
continue
}
if err := utils.UnmarshalJSONToProtoV1([]byte(share), &local.PublicShare); err != nil {
log.Error().Err(err).Msg("error unmarshalling share")
continue
}The unmarshal branch has the same outcome and the same fix, even though it predates this PR.
| if err := localCtx.Err(); err != nil { | ||
| if stderr.Is(err, context.DeadlineExceeded) { | ||
| log.Info().Err(err).Msg("resolveLinkshares: deadline exceeded") | ||
| span.SetStatus(codes.Error, err.Error()) | ||
| } | ||
| break | ||
| } |
There was a problem hiding this comment.
Passing localCtx into ListPublicShares below is the part that matters - that is what stops a stalled share manager from holding the PROPFIND open for the caller's full timeout.
This check cannot fire, though. The loop body does nothing but two string comparisons until the one iteration that matches, and that iteration ends in break. So localCtx.Err() is only ever non-nil if the parent ctx was already done on entry - in which case one check before the loop says the same thing, and without the DeadlineExceeded-only filter that currently swallows Canceled. Dropping it also removes the need for the stderr "errors" import alias.
| ProductName string `mapstructure:"product_name"` | ||
| ProductVersion string `mapstructure:"product_version"` | ||
| AllowPropfindDepthInfinitiy bool `mapstructure:"allow_depth_infinity"` | ||
| DisablePropfindPublicLinkResolution bool `mapstructure:"disable_propfind_public_link_resolution"` |
There was a problem hiding this comment.
This commit adds a user-visible config option plus a hardcoded 10s bound in resolveLinkshares, after which share indicators are silently omitted from the PROPFIND response rather than surfaced as an error. There is no changelog/unreleased/ entry for it, although the other commits in this PR each add one.
Worth one, especially on a stable branch: "share indicators missing" is hard to trace back to a release without a note, and this option is the operator-facing knob for it.
kobergj
left a comment
There was a problem hiding this comment.
Three smaller issue - none of them critical 👍
* fix: Fixed the revok during the least/read operations and the mutex in a public shares * fix: [OCISDEV-1433] bound the machine auth call of the metadata storage The cs3 metadata storage authenticates as a system user before every operation, and that Authenticate call carried no deadline. A gateway that accepted the connection but never answered it - because it was itself waiting on a stalled storage provider - parked the calling goroutine for the lifetime of the process, with no log output at all. The call now runs on its own bounded context and logs a warning when the deadline is exhausted. The context returned to the caller deliberately keeps no deadline: callers run their own RPC on it after getAuthContext returns. Adds the first tests for this package, including one that reproduces the unbounded wait against an in-process gateway that never answers. * fix: [OCISDEV-1433] detect grpc peers that stop answering The grpc client connections of the pool were created without keepalive parameters, so a peer that stopped answering on an established connection - a black-holed node, a wedged process - was indistinguishable from a peer that was merely slow, and a request without a deadline waited for the lifetime of the process. The clients now ping the peer while a request is in flight and fail the requests on a connection that does not answer, tunable with GRPC_CLIENT_KEEPALIVE_TIME and GRPC_CLIENT_KEEPALIVE_TIMEOUT. The servers got the matching enforcement policy so they accept those pings. GRPC_MAX_CONNECTION_AGE is removed along with it. It closed healthy connections on a timer, never ended a request that was already in flight because the grace period was left at infinity, and fell back to doing nothing at all whenever its value had no unit suffix. * fix: fixed the lazy load mutex * move resolveLinkshares to the dedicated function * rewok the default keepalive.ClientParameters * update the public share manager * fix: Disable the resolution of public link shares when answering PROPFIND requests. * fix: Invalidate the cache after write. Moved the db copy from the persist label to the manager. * fix: fix unsafe type assertions, to avoid the panic * fix: The keepalive grpc clinet configuration updated --------- Co-authored-by: Claude Opus 5 <[email protected]>
* fix: Fixed the revok during the least/read operations and the mutex in a public shares * fix: [OCISDEV-1433] bound the machine auth call of the metadata storage The cs3 metadata storage authenticates as a system user before every operation, and that Authenticate call carried no deadline. A gateway that accepted the connection but never answered it - because it was itself waiting on a stalled storage provider - parked the calling goroutine for the lifetime of the process, with no log output at all. The call now runs on its own bounded context and logs a warning when the deadline is exhausted. The context returned to the caller deliberately keeps no deadline: callers run their own RPC on it after getAuthContext returns. Adds the first tests for this package, including one that reproduces the unbounded wait against an in-process gateway that never answers. * fix: [OCISDEV-1433] detect grpc peers that stop answering The grpc client connections of the pool were created without keepalive parameters, so a peer that stopped answering on an established connection - a black-holed node, a wedged process - was indistinguishable from a peer that was merely slow, and a request without a deadline waited for the lifetime of the process. The clients now ping the peer while a request is in flight and fail the requests on a connection that does not answer, tunable with GRPC_CLIENT_KEEPALIVE_TIME and GRPC_CLIENT_KEEPALIVE_TIMEOUT. The servers got the matching enforcement policy so they accept those pings. GRPC_MAX_CONNECTION_AGE is removed along with it. It closed healthy connections on a timer, never ended a request that was already in flight because the grace period was left at infinity, and fell back to doing nothing at all whenever its value had no unit suffix. * fix: fixed the lazy load mutex * move resolveLinkshares to the dedicated function * rewok the default keepalive.ClientParameters * update the public share manager * fix: Disable the resolution of public link shares when answering PROPFIND requests. * fix: Invalidate the cache after write. Moved the db copy from the persist label to the manager. * fix: fix unsafe type assertions, to avoid the panic * fix: The keepalive grpc clinet configuration updated --------- Co-authored-by: Claude Opus 5 <[email protected]>
Related:
#757
Change: [OCISDEV-1433] Replace GRPC_MAX_CONNECTION_AGE with client keepalive
The grpc clients can now send a keepalive ping while a request is in flight and
fail the requests on a connection whose peer stops answering, instead of waiting
for as long as the caller allows. Set GRPC_CLIENT_KEEPALIVE_TIME to a duration
such as '20s' to enable this; GRPC_CLIENT_KEEPALIVE_TIMEOUT is how long the
answer to a ping is waited for and defaults to '10s'. Leaving the keepalive time
unset sends no pings at all, which is grpc's own behavior.
GRPC_MAX_CONNECTION_AGE has been removed. It only closed healthy connections on
a timer, never ended a request that was already in flight, and silently did
nothing when its value had no unit suffix.
Bugfix: [OCISDEV-1433] Bound the machine auth call of the metadata storage
The cs3 metadata storage authenticates as a system user before every operation,
and that Authenticate call was issued without a deadline. A gateway that
accepted the connection but never answered it - because it was itself waiting
on a stalled storage provider - therefore parked the calling goroutine for the
lifetime of the process, without any log output. The call now runs with a
timeout and logs a warning when it is exhausted, so a stalled downstream
surfaces as an error instead of a silent, unrecoverable wait.
Bugfix: Harden the json public share manager against races, panics and leaks
The json public share manager (pkg/publicshare/manager/json) and its cs3
persistence backend received a round of concurrency and lifecycle fixes:
(Dump, GetPublicShare, ListPublicShares, GetPublicShareByToken) takes an
RLock instead of a full Lock, so concurrent reads no longer serialize
behind each other.
RevokePublicShare, the janitor) now mutates its own copy of the share
database instead of the map returned by Read, since that map can alias
the persistence layer's cache and be shared with concurrent readers. The
in-memory and cs3 persistence backends were adjusted to match this
copy-on-write contract.
atomic.Bool guarded by its own mutex, so already-initialized callers no
longer contend with each other or with in-flight reads for a single lock.
Its mtime-based read cache is now itself guarded by a mutex, and a
successful Write invalidates that cache so a subsequent Read is forced to
refetch instead of serving a stale entry.
know when to stop. The manager now exposes a Close(ctx) method
(publicshare.ClosableManager) that cancels the janitor's context and waits
for its goroutine to exit; the publicshareprovider gRPC service calls it
on shutdown with a bounded timeout instead of doing nothing.
revoke an expired share inline while serving a read; they just treat it
as not found/skip it. Actual deletion is left to the janitor, which now
removes expired entries directly instead of recursively calling back into
RevokePublicShare.
(e.g. v.(map[string]interface{})["share"].(string)) were replaced by a
helper that reports failure instead of panicking, so a single malformed
or legacy entry in publicshares.json no longer crash-loops the janitor or
fails a request. The "password" field is treated as optional, since
shares without password protection never had one to begin with.