ratchetphp/Ratchet · error · RuntimeException
Can not change session name in VirtualProxy
Error message
Can not change session name in VirtualProxy
What it means
VirtualProxyForSymfony6 is the Symfony 6 compatible variant of the VirtualProxy and, like it, forbids changing the session name after the proxy is created; setName() unconditionally throws RuntimeException. The name is fixed by the underlying session storage for the lifetime of the proxy.
Solutions
- Do not call setName on the proxy; configure the session name before the Ratchet server starts (session_name() or session config).
- Remove or guard any library/framework code path that mutates the session name while the proxy is active.
- If a different session name is genuinely required, create the SessionProvider/session storage with the desired name from the start.
Example fix
// before
$session->setName('APP_SESSION'); // proxy -> RuntimeException
// after
// during bootstrap, before server start:
ini_set('session.name', 'APP_SESSION'); Defensive patterns
Strategy: type-guard
Validate before calling
if ($session instanceof \Ratchet\Session\Storage\Proxy\VirtualProxyForSymfony6) {
throw new \LogicException('Configure the session name in Symfony config; the proxy is immutable.');
} Type guard
function canRenameSession($session): bool {
return !$session instanceof \Ratchet\Session\Storage\Proxy\VirtualProxyForSymfony6;
} Try / catch
try {
$session->setName($name);
} catch (\RuntimeException $e) {
// set the name via framework config or session_name() at bootstrap instead
} Prevention
- Configure session name in Symfony framework.yaml (session.name) rather than runtime calls.
- Guard third-party code that mutates the session name per-request.
- Set session.name via ini before starting the Ratchet server.
When it happens
Trigger: Calling setName($name) on the Symfony 6 virtual session proxy, directly or indirectly through code that assumes a fully mutable SessionInterface.
Common situations: Symfony 6 applications calling $session->setName() at runtime; bundles or middleware that mutate the session name per-request while the Ratchet session is wrapped in this proxy.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Can not change session name in VirtualProxy
- Can not change session name in VirtualProxy
- Handler must be instance of SessionHandlerInterface
- Argument #4 ($serializer) expected…
- Unable to parse session serialize handler
AI-assisted analysis of ratchetphp/Ratchet@e621c6c40b (2026-09-16).
Data as JSON: /api/errors/692903a08a00efd4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ratchet/Session/Storage/Proxy/VirtualProxyForSymfony6.php:58
* {@inheritdoc}
*/
public function setId($id) {
$this->_sessionId = $id;
}
/**
* {@inheritdoc}
*/
public function getName(): string {
return $this->_sessionName;
}
/**
* DO NOT CALL THIS METHOD
* @internal
*/
public function setName($name) {
throw new \RuntimeException("Can not change session name in VirtualProxy");
}
}
View on GitHub (pinned to e621c6c40b)