detached 8a8ae4c

docs: analysis diff

commit
8a8ae4c439cc1f85617a78d73e735305104f171b
author
bamen · · 2025-03-24 06:36 UTC
parent
7012c85
signature
unsigned
1 file · +71 -0
A PROXY_ANALYSIS.md +71 -0
@@ -0,0 +1,71 @@
1+# Proxy Server Analysis: `feat/templ-integration` vs `dev` Branch
2+
3+## Key Issue
4+The proxy server in the `feat/templ-integration` branch is no longer receiving requests on both HTTP and HTTPS ports, while it worked properly in the `dev` branch.
5+
6+## Root Causes
7+
8+1. **Server Binding Method Changed**:
9+ - **dev branch (working)**: Uses standard approach with `httpServer.ListenAndServe()` and `httpsServer.ListenAndServeTLS("", "")`
10+ - **templ-integration branch (broken)**: Uses explicit IPv4 binding with `net.Listen("tcp4", "0.0.0.0:port")` first, then falls back if that fails
11+
12+2. **Port Configuration Modifications**:
13+ - **templ-integration branch** added a new `configureProxyPorts()` function that automatically changes privileged ports to non-privileged ones for non-root users
14+ - Port 80 → 8080 and port 443 → 8443 when running outside containers as non-root
15+
16+3. **Enhanced Admin Route Handling**:
17+ - More complex admin route handling with several verification steps and recovery mechanisms
18+ - Multiple connection tests and fallbacks can create race conditions
19+
20+4. **Port Conflict Detection**:
21+ - More aggressive conflict detection which might be incorrectly disabling the proxy
22+
23+## Specific Code Differences
24+
25+### Server Binding
26+```go
27+// templ-integration (broken)
28+// First try explicit IPv4 binding
29+httpsAddr := fmt.Sprintf("0.0.0.0:%s", p.config.Port)
30+tcpListener, err := net.Listen("tcp4", httpsAddr)
31+
32+if err != nil {
33+ logger.Warn("Failed to create HTTPS listener...")
34+ // Try simple binding as fallback
35+ if err := httpsServer.ListenAndServeTLS("", ""); err != nil {
36+ logger.Error("HTTPS server failed", "error", err)
37+ }
38+ return
39+}
40+
41+// Create TLS listener
42+tlsListener := tls.NewListener(tcpListener, httpsServer.TLSConfig)
43+if err := httpsServer.Serve(tlsListener); err != nil {
44+ logger.Error("HTTPS server failed", "error", err)
45+}
46+
47+// dev branch (working)
48+logger.Info("Starting HTTPS server", "address", httpsServer.Addr)
49+// Using empty strings for cert and key files since we're using GetCertificate
50+if err := httpsServer.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {
51+ logger.Error("HTTPS server failed", "error", err)
52+}
53+```
54+
55+### Testing and Verification
56+The `templ-integration` branch adds extensive connection testing code:
57+- Port binding verification
58+- Multiple hostname tests
59+- Complex fallback mechanisms
60+- Periodic admin route verification
61+
62+## Recommended Fix
63+
64+To fix the issue, we should:
65+
66+1. Revert to the simple binding method from the `dev` branch in both `startHTTPSServer()` and `startHTTPServer()` functions
67+2. Simplify the admin connection testing logic
68+3. Keep the port conflict detection but ensure it doesn't incorrectly disable the proxy
69+4. Review the container environment detection to ensure it works properly
70+
71+The simplest fix would be to modify the server binding methods to use the direct approach from the `dev` branch that was working correctly.⏎̸
@@ -0,0 +1,71 @@
1+# Proxy Server Analysis: `feat/templ-integration` vs `dev` Branch
2+
3+## Key Issue
4+The proxy server in the `feat/templ-integration` branch is no longer receiving requests on both HTTP and HTTPS ports, while it worked properly in the `dev` branch.
5+
6+## Root Causes
7+
8+1. **Server Binding Method Changed**:
9+ - **dev branch (working)**: Uses standard approach with `httpServer.ListenAndServe()` and `httpsServer.ListenAndServeTLS("", "")`
10+ - **templ-integration branch (broken)**: Uses explicit IPv4 binding with `net.Listen("tcp4", "0.0.0.0:port")` first, then falls back if that fails
11+
12+2. **Port Configuration Modifications**:
13+ - **templ-integration branch** added a new `configureProxyPorts()` function that automatically changes privileged ports to non-privileged ones for non-root users
14+ - Port 80 → 8080 and port 443 → 8443 when running outside containers as non-root
15+
16+3. **Enhanced Admin Route Handling**:
17+ - More complex admin route handling with several verification steps and recovery mechanisms
18+ - Multiple connection tests and fallbacks can create race conditions
19+
20+4. **Port Conflict Detection**:
21+ - More aggressive conflict detection which might be incorrectly disabling the proxy
22+
23+## Specific Code Differences
24+
25+### Server Binding
26+```go
27+// templ-integration (broken)
28+// First try explicit IPv4 binding
29+httpsAddr := fmt.Sprintf("0.0.0.0:%s", p.config.Port)
30+tcpListener, err := net.Listen("tcp4", httpsAddr)
31+
32+if err != nil {
33+ logger.Warn("Failed to create HTTPS listener...")
34+ // Try simple binding as fallback
35+ if err := httpsServer.ListenAndServeTLS("", ""); err != nil {
36+ logger.Error("HTTPS server failed", "error", err)
37+ }
38+ return
39+}
40+
41+// Create TLS listener
42+tlsListener := tls.NewListener(tcpListener, httpsServer.TLSConfig)
43+if err := httpsServer.Serve(tlsListener); err != nil {
44+ logger.Error("HTTPS server failed", "error", err)
45+}
46+
47+// dev branch (working)
48+logger.Info("Starting HTTPS server", "address", httpsServer.Addr)
49+// Using empty strings for cert and key files since we're using GetCertificate
50+if err := httpsServer.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {
51+ logger.Error("HTTPS server failed", "error", err)
52+}
53+```
54+
55+### Testing and Verification
56+The `templ-integration` branch adds extensive connection testing code:
57+- Port binding verification
58+- Multiple hostname tests
59+- Complex fallback mechanisms
60+- Periodic admin route verification
61+
62+## Recommended Fix
63+
64+To fix the issue, we should:
65+
66+1. Revert to the simple binding method from the `dev` branch in both `startHTTPSServer()` and `startHTTPServer()` functions
67+2. Simplify the admin connection testing logic
68+3. Keep the port conflict detection but ensure it doesn't incorrectly disable the proxy
69+4. Review the container environment detection to ensure it works properly
70+
71+The simplest fix would be to modify the server binding methods to use the direct approach from the `dev` branch that was working correctly.⏎̸

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close