fix: domain change exits early in non-TTY, engine never restarts#64
Merged
SamNet-dev merged 1 commit intoApr 12, 2026
Merged
Conversation
When running without a TTY (e.g. ssh host 'mtproxymax domain newdomain'), the bare 'read -r _rot' returns exit code 1 (EOF). With set -eo pipefail active, this causes the script to exit immediately — before secret rotation and before restart_proxy_container is called. The engine continues running with the old domain in memory, silently rejecting all client connections from the new SNI as 'unknown SNI'. Fix: - Check [ -t 0 ] before attempting read - Default _rot to 'y' (rotate + restart) in non-interactive mode - Add read || _rot='y' guard for interactive mode too (rare edge case) - Print informational message so non-interactive callers know what happened
Owner
|
Great catch and excellent write-up. Merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
mtproxymax domain <new>is run without a TTY — for example via a non-interactive SSH command, a CI script, or the Telegram bot — the script exits silently before restarting the engine. The result:settings.confandconfig.tomlare updated with the new domain, but the running telemt container continues using the old domain in memory. Every client connection using the new domain's SNI is rejected asunknown SNIand forwarded to the masking target instead.Root cause
The script uses
set -eo pipefail(line 10). Line 7083 contains a bareread:When stdin is not a TTY,
readreceives immediate EOF and returns exit code 1. Withset -eactive, the script exits here — beforesave_secretsand beforerestart_proxy_containerare ever reached.The output appears successful (
[✓] Domain changed to ...) because the log line runs beforeread, so callers have no indication anything went wrong.Observed symptoms
Note: even sending
SIGHUP(viamtproxymax secret add/remove) does not fix this — telemt does not reloadtls_domainfrom SIGHUP, only secrets. A full container restart is required.Fix
Check
[ -t 0 ]before attemptingread. Default toy(rotate + restart) in non-interactive mode, print an informational message so the caller knows what happened, and add a|| _rot="y"guard on the interactive path as well.The default of
y(rotate) is the safest choice: after a domain change, old secrets encode the old domain, so rotating them ensures distributed links work immediately after restart.Related
domain clearpath (same file, a few lines above) correctly callsrestart_proxy_containerwithout anyreadguard — this fix brings thedomain setpath into parity.Testing
Interactive (unchanged behaviour):
mtproxymax domain www.newdomain.com # Prompts as before, rotates on Y, skips on N, restarts in both casesNon-interactive (fixed):