Skip to content

Fix/ocisdev 1433 - #748

Merged
2403905 merged 11 commits into
stable-8.0from
fix/OCISDEV-1433
Oct 1, 2026
Merged

2403905 merged 11 commits into
stable-8.0from
fix/OCISDEV-1433

Conversation

@2403905

@2403905 2403905 commented Sep 25, 2026 •

Copy link
Copy Markdown

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:

  • The manager's mutex is now a sync.RWMutex, and every read-only operation
    (Dump, GetPublicShare, ListPublicShares, GetPublicShareByToken) takes an
    RLock instead of a full Lock, so concurrent reads no longer serialize
    behind each other.
  • Every write path (Load, CreatePublicShare, UpdatePublicShare,
    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.
  • The cs3 persistence backend's one-time initialization flag is now an
    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.
  • The janitor no longer subscribes to OS signals (SIGHUP/SIGINT/SIGQUIT) to
    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.
  • GetPublicShare, ListPublicShares and GetPublicShareByToken no longer
    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.
  • Unchecked type assertions on the persisted "share" and "password" fields
    (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.
  • The default janitor run interval changed from 60 seconds to 1 hour.

@kw-security

kw-security commented Sep 25, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kobergj kobergj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread pkg/publicshare/manager/json/json.go Resolved
Comment thread pkg/publicshare/manager/json/json.go Resolved
Comment thread pkg/publicshare/manager/json/json.go Resolved
Comment thread pkg/publicshare/manager/json/json.go Resolved
@2403905
2403905 marked this pull request as ready for review September 29, 2026 07:18
@2403905
2403905 requested a review from kobergj September 29, 2026 07:18
2403905 and others added 9 commits September 29, 2026 12:14
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]>

@kobergj kobergj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Write mtime/content inconsistency is fixed by invalidating instead of syncing, and cs3_write_test.go pins 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
  • Copy moved to the write paths and Read is documented read-only, with TestReadDoesNotCopyTheDatabase bounding 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.

Comment on lines +145 to +147
// Invalidate the cache to minimize the risk of inconsistency.
p.db.mtime = time.Time{}
p.db.publicShares = persistence.PublicShares{}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = true

with 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.

Comment on lines +262 to 268
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")
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +510 to +516
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
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kobergj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three smaller issue - none of them critical 👍

@2403905
2403905 merged commit 9557cab into stable-8.0 Oct 1, 2026
23 of 25 checks passed
@2403905
2403905 deleted the fix/OCISDEV-1433 branch October 1, 2026 15:01
2403905 added a commit that referenced this pull request Oct 2, 2026
* 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]>
2403905 added a commit that referenced this pull request Oct 5, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants