Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/OpenSlides/openslides-autoupdate-service
go 1.25.0

require (
github.com/OpenSlides/openslides-go v0.0.0-20260206065132-09fa1a890081
github.com/OpenSlides/openslides-go v0.0.0-20260219070754-9224a36bfe96
github.com/alecthomas/kong v1.13.0
github.com/jackc/pgx/v5 v5.8.0
github.com/klauspost/compress v1.18.2
github.com/ostcar/topic v0.6.0
github.com/zeebo/xxh3 v1.0.2
Expand All @@ -16,7 +17,6 @@ require (
github.com/gomodule/redigo v1.9.3 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.8.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -27,3 +27,5 @@ require (
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
)

replace github.com/OpenSlides/openslides-go => github.com/kryptance/openslides-go v0.0.0-20260219070754-9224a36bfe96

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use the go work feature with the same effect without editing this file.

go work init . ../openslides-go

4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/OpenSlides/openslides-go v0.0.0-20260206065132-09fa1a890081 h1:/pJdLneXnN6geusS7zIwTnaNX82xT7GAVvTk396cyZk=
github.com/OpenSlides/openslides-go v0.0.0-20260206065132-09fa1a890081/go.mod h1:Gsmd/Ex1YnCvMVVxU3Hu4Qyopfi1bMJwcMde+QGz2fI=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v1.13.0 h1:5e/7XC3ugvhP1DQBmTS+WuHtCbcv44hsohMgcvVxSrA=
Expand Down Expand Up @@ -55,6 +53,8 @@ github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uq
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kryptance/openslides-go v0.0.0-20260219070754-9224a36bfe96 h1:nlMB94u2j+lWht1huyAzjFimlYLdk0mCyQTVkPHyj2s=
github.com/kryptance/openslides-go v0.0.0-20260219070754-9224a36bfe96/go.mod h1:Gsmd/Ex1YnCvMVVxU3Hu4Qyopfi1bMJwcMde+QGz2fI=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down
6 changes: 6 additions & 0 deletions internal/autoupdate/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/OpenSlides/openslides-go/datastore/cache"
"github.com/OpenSlides/openslides-go/datastore/flow"
"github.com/OpenSlides/openslides-go/environment"
"github.com/jackc/pgx/v5/pgxpool"
)

// Flow is the connection to the database for the autoupdate service.
Expand Down Expand Up @@ -72,6 +73,11 @@ func (f *Flow) ResetCache() {
f.cache.Reset()
}

// Pool returns the underlying postgres connection pool.
func (f *Flow) Pool() *pgxpool.Pool {
return f.postgres.Pool
}

func (f *Flow) metric(values metric.Container) {
values.Add("datastore_cache_key_len", f.cache.Len())
values.Add("datastore_cache_size", f.cache.Size())
Expand Down
12 changes: 12 additions & 0 deletions internal/http/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ func (e invalidRequestError) Error() string {
func (e invalidRequestError) Type() string {
return "invalid_request"
}

// logoutError is sent when a session is terminated due to server-initiated logout
// (e.g., backchannel logout from Keycloak).
type logoutError struct{}

func (e logoutError) Error() string {
return "Session logged out"
}

func (e logoutError) Type() string {
return "logout"
}
26 changes: 20 additions & 6 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/OpenSlides/openslides-autoupdate-service/internal/autoupdate"
"github.com/OpenSlides/openslides-autoupdate-service/internal/keysbuilder"
"github.com/OpenSlides/openslides-autoupdate-service/internal/metric"
"github.com/OpenSlides/openslides-go/auth"
"github.com/OpenSlides/openslides-go/datastore/dskey"
"github.com/OpenSlides/openslides-go/oserror"
"github.com/OpenSlides/openslides-go/redis"
Expand Down Expand Up @@ -145,7 +146,7 @@ func autoupdateHandler(auth Authenticater, connecter Connecter, heartbeat time.D
if isLongPolling {
if headersSent, err := handleLongpolling(ctx, w, uid, builder, connecter, compress, hashes); err != nil {
if headersSent {
handleErrorWithoutStatus(w, err)
handleErrorWithoutStatusCtx(ctx, w, err)
} else {
handleErrorWithStatus(w, err)
}
Expand All @@ -154,7 +155,7 @@ func autoupdateHandler(auth Authenticater, connecter Connecter, heartbeat time.D
}

if err := sendMessages(ctx, w, uid, builder, connecter, compress, heartbeat); err != nil {
handleErrorWithoutStatus(w, err)
handleErrorWithoutStatusCtx(ctx, w, err)
return
}
})
Expand Down Expand Up @@ -502,17 +503,21 @@ func internalAuthMiddleware(next http.Handler, auth Authenticater) http.Handler
}

func handleErrorWithStatus(w http.ResponseWriter, err error) {
handleError(w, err, true, false)
handleError(nil, w, err, true, false)
}

func handleErrorWithoutStatus(w http.ResponseWriter, err error) {
handleError(w, err, false, false)
handleError(nil, w, err, false, false)
}

func handleErrorWithoutStatusCtx(ctx context.Context, w http.ResponseWriter, err error) {
handleError(ctx, w, err, false, false)
}

// handleErrorInternal is only for internal request routes. It returns the full
// error message to the client.
func handleErrorInternal(w http.ResponseWriter, err error) {
handleError(w, err, true, true)
handleError(nil, w, err, true, true)
}

// handleError interprets the given error and writes a corresponding message to
Expand All @@ -523,11 +528,20 @@ func handleErrorInternal(w http.ResponseWriter, err error) {
//
// If the handler already started to write the body then it is not allowed to
// set the http-status-code. In this case, writeStatusCode has to be fales.
func handleError(w http.ResponseWriter, err error, writeStatusCode bool, internal bool) {
func handleError(ctx context.Context, w http.ResponseWriter, err error, writeStatusCode bool, internal bool) {
if writeStatusCode {
w.Header().Set("Content-Type", "application/octet-stream")
}

// Check for server-initiated logout (backchannel logout)
if ctx != nil && oserror.ContextDone(err) {
if cause := context.Cause(ctx); cause != nil {
if _, isLogout := cause.(auth.LogoutError); isLogout {
err = logoutError{}
}
}
}

if oserror.ContextDone(err) || errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) {
// Client closed connection.
return
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func initService(lookup environment.Environmenter) (func(context.Context) error,
backgroundTasks = append(backgroundTasks, flowBackground)

// Auth Service.
authService, authBackground, err := auth.New(lookup, messageBus)
authService, authBackground, err := auth.New(lookup, messageBus, flow.Pool())
if err != nil {
return nil, fmt.Errorf("init connection to auth: %w", err)
}
Expand Down
Loading