proxy

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(srv *server.Server) http.Handler

Handler returns an http.Handler that proxies requests to Shiny app workers. It manages session cookies, cold-starts workers on demand, and forwards HTTP and WebSocket traffic.

The returned handler captures a shared WsCache and http.Transport that persist for the server's lifetime.

func RedirectTrailingSlash

func RedirectTrailingSlash(w http.ResponseWriter, r *http.Request)

RedirectTrailingSlash redirects /app/{name} to /app/{name}/. Shiny apps use relative URLs for assets and WebSocket connections, so the trailing slash is required for correct path resolution.

func RunAutoscaler added in v0.0.2

func RunAutoscaler(ctx context.Context, srv *server.Server)

RunAutoscaler runs as a background goroutine alongside health polling. On each tick it:

  • Sweeps sessions that have been idle longer than the configured TTL.
  • Marks workers with zero sessions as idle (sets IdleSince).
  • Evicts workers that have been idle beyond idle_worker_timeout.
  • Evicts workers that have crashed (health check fails).
  • Spawns a new worker if all existing workers are at capacity and the per-app and global limits allow it (eager scale-up).
  • Maintains pre-warmed worker pools for configured apps.

Blocks until ctx is cancelled.

Types

type LoadBalancer added in v0.0.2

type LoadBalancer struct{}

LoadBalancer assigns new sessions to workers using a least-loaded strategy. Stateless — decisions are based on current worker and session state at call time.

func (*LoadBalancer) Assign added in v0.0.2

func (lb *LoadBalancer) Assign(
	appID string,
	workers server.WorkerMap,
	sessions session.Store,
	maxSessionsPerWorker int,
	maxWorkersPerApp *int,
) (string, error)

Assign picks a worker for a new session belonging to appID.

Returns a worker ID when an existing worker has available capacity. Returns ("", nil) when no worker has capacity but the per-app limit has not been reached — the caller should spawn a new worker. Returns errCapacityExhausted when all workers are full and the per-app limit has been reached.

type WsCache

type WsCache struct {
	// contains filtered or unexported fields
}

WsCache holds backend readers after client disconnect. Keyed by session ID. Entries expire after a configurable TTL.

func NewWsCache

func NewWsCache() *WsCache

func (*WsCache) Cache

func (c *WsCache) Cache(sessionID string, reader *backendReader, ttl time.Duration, onExpire func())

Cache stores a backend reader with a TTL. When the TTL expires, the reader is closed and onExpire is called.

func (*WsCache) Take

func (c *WsCache) Take(sessionID string) *backendReader

Take reclaims a cached backend reader. Returns nil if no entry exists. Stops the expiry timer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL