proxy

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: GPL-3.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 WebSocket state at call time.

func (*LoadBalancer) Assign added in v0.0.2

func (lb *LoadBalancer) Assign(
	appID string,
	workers server.WorkerMap,
	wsConns *server.WsConnCounter,
	maxSessionsPerWorker int,
	maxWorkersPerApp *int,
) (string, error)

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

A session here is one active Shiny WebSocket (one tab). Load is measured via the WsConnCounter: handshakes that have been accepted and haven't closed yet. The cookie-level session store tracks browser-to-worker pinning for HTTP routing but does not gate capacity — two tabs in the same browser share the cookie but open two distinct WebSockets, so the counter sees the second tab.

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