From 2667a3e516e7ecc574676a1a5f65d0c58077da2f Mon Sep 17 00:00:00 2001 From: G-Akleh Date: Tue, 9 Jun 2026 22:16:09 +0300 Subject: [PATCH 1/3] docs: add PR template Signed-off-by: G-Akleh --- .github/pull_request_template.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..1a68db5e5 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,13 @@ +## Goal + + +## Changes +- + +## Testing + + +## Checklist +- [ ] Title is a clear sentence (≤ 70 chars) +- [ ] Commits are signed (`git log --show-signature`) +- [ ] `submissions/labN.md` updated From 781ab23f23d6668aaa417ac5f5663dce7cc90190 Mon Sep 17 00:00:00 2001 From: G-Akleh Date: Tue, 9 Jun 2026 23:46:35 +0300 Subject: [PATCH 2/3] docs: upstream moved while you worked Signed-off-by: G-Akleh From 5645c93048fba498af70da5c1c166c473eb04bcb Mon Sep 17 00:00:00 2001 From: G-Akleh Date: Wed, 17 Jun 2026 00:42:39 +0300 Subject: [PATCH 3/3] docs(lab4): add OS and networking debugging documentation Signed-off-by: G-Akleh --- lab4-trace.pcap | Bin 0 -> 1440 bytes lab4-trace.txt | 43 +++++ submissions/lab4.md | 411 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 454 insertions(+) create mode 100644 lab4-trace.pcap create mode 100644 lab4-trace.txt create mode 100644 submissions/lab4.md diff --git a/lab4-trace.pcap b/lab4-trace.pcap new file mode 100644 index 0000000000000000000000000000000000000000..cbf9b6be3d3fc7887c968ebcc3d81d52648914e6 GIT binary patch literal 1440 zcmb`H&ui0Q7{}i>#YrSEy;u;|m*8QJ{z%#_Yjbi;bco`>sJO#4OJCcREa{TB$dp1) zp7$rrvpabhyF1pKCy`ye3$h)(*5_HHQnMqe&VPhqP0mJqJ3ja1Caov1dyI zG1Hk%5;707B>Hn931_;sA&?YU!4<9nR@l*IQkx4FY)UFN=NF}lsRfK4lR0n_VIFgiVSbQv268^>%qDt&GoRlP$ZfEWD_me6Dd+z-KSn|Gzc0NAtG>PSzNzI$+)PK_4JQdOf5TQ1yQ)Zjy3(sWg!4;~w%9~nBXl=_bCs;sM} zY%JGV+3NqNS0;xLkdjlhoT?c^R=!wNl**#Aydk$mOy)i~i%16ddyHfT`~3v=#MwkL t= ::1.8080: Flags [S], seq 2060989463, win 65476, options [mss 65476,sackOK,TS val 1474851703 ecr 0,nop,wscale 7], length 0 +`.g7.(.@....................................z.4..........0......... +W.sw........ +23:56:10.219591 IP6 ::1.8080 > ::1.46764: Flags [S.], seq 695416862, ack 2060989464, win 65464, options [mss 65476,sackOK,TS val 1474851703 ecr 1474851703,nop,wscale 7], length 0 +`..^.(.@....................................)s8.z.4......0......... +W.swW.sw.... +23:56:10.219608 IP6 ::1.46764 > ::1.8080: Flags [.], ack 1, win 512, options [nop,nop,TS val 1474851703 ecr 1474851703], length 0 +`.g7. .@....................................z.4.)s8......(..... +W.swW.sw +23:56:10.219675 IP6 ::1.46764 > ::1.8080: Flags [P.], seq 1:175, ack 1, win 512, options [nop,nop,TS val 1474851703 ecr 1474851703], length 174: HTTP: POST /notes HTTP/1.1 +`.g7...@....................................z.4.)s8............ +W.swW.swPOST /notes HTTP/1.1 +Host: localhost:8080 +User-Agent: curl/8.5.0 +Accept: */* +Content-Type: application/json +Content-Length: 39 + +{"title":"trace me","body":"in flight"} +23:56:10.219678 IP6 ::1.8080 > ::1.46764: Flags [.], ack 175, win 511, options [nop,nop,TS val 1474851703 ecr 1474851703], length 0 +`..^. .@....................................)s8.z.4......(..... +W.swW.sw +23:56:10.225582 IP6 ::1.8080 > ::1.46764: Flags [P.], seq 1:207, ack 175, win 512, options [nop,nop,TS val 1474851709 ecr 1474851703], length 206: HTTP: HTTP/1.1 201 Created +`..^...@....................................)s8.z.4............ +W.s}W.swHTTP/1.1 201 Created +Content-Type: application/json +Date: Tue, 16 Jun 2026 20:56:10 GMT +Content-Length: 93 + +{"id":13,"title":"trace me","body":"in flight","created_at":"2026-06-16T20:56:10.22009407Z"} + +23:56:10.225606 IP6 ::1.46764 > ::1.8080: Flags [.], ack 207, win 511, options [nop,nop,TS val 1474851709 ecr 1474851709], length 0 +`.g7. .@....................................z.4.)s8......(..... +W.s}W.s} +23:56:10.225771 IP6 ::1.46764 > ::1.8080: Flags [F.], seq 175, ack 207, win 512, options [nop,nop,TS val 1474851709 ecr 1474851709], length 0 +`.g7. .@....................................z.4.)s8......(..... +W.s}W.s} +23:56:10.225826 IP6 ::1.8080 > ::1.46764: Flags [F.], seq 207, ack 176, win 512, options [nop,nop,TS val 1474851709 ecr 1474851709], length 0 +`..^. .@....................................)s8.z.4......(..... +W.s}W.s} +23:56:10.225840 IP6 ::1.46764 > ::1.8080: Flags [.], ack 208, win 512, options [nop,nop,TS val 1474851709 ecr 1474851709], length 0 +`.g7. .@....................................z.4.)s8......(..... +W.s}W.s} diff --git a/submissions/lab4.md b/submissions/lab4.md new file mode 100644 index 000000000..0307deb3f --- /dev/null +++ b/submissions/lab4.md @@ -0,0 +1,411 @@ +# Lab 4 Submssion + +## Task 1 + +### Request sent using curl output + +```bash +curl -v -X POST http://localhost:8080/notes \ + -H 'Content-Type: application/json' \ + -d '{"title":"trace me","body":"in flight"}' +Note: Unnecessary use of -X or --request, POST is already inferred. +* Host localhost:8080 was resolved. +* IPv6: ::1 +* IPv4: 127.0.0.1 +* Trying [::1]:8080... +* Connected to localhost (::1) port 8080 +> POST /notes HTTP/1.1 +> Host: localhost:8080 +> User-Agent: curl/8.5.0 +> Accept: */* +> Content-Type: application/json +> Content-Length: 39 +> +< HTTP/1.1 201 Created +< Content-Type: application/json +< Date: Tue, 16 Jun 2026 20:56:10 GMT +< Content-Length: 93 +< +{"id":13,"title":"trace me","body":"in flight","created_at":"2026-06-16T20:56:10.22009407Z"} +* Connection #0 to host localhost left intact +``` + +### TCP Three-Way Handshake + +#### SYN (Client → Server) + +```text +23:56:10.219563 IP6 ::1.46764 > ::1.8080: Flags [S] +``` + +The client initiates a new TCP connection to QuickNotes on port 8080 by sending a SYN packet. + +#### SYN/ACK (Server → Client) + +```text +23:56:10.219591 IP6 ::1.8080 > ::1.46764: Flags [S.] +``` + +QuickNotes acknowledges the SYN and sends its own SYN to establish the connection. + +#### ACK (Client → Server) + +```text +23:56:10.219608 IP6 ::1.46764 > ::1.8080: Flags [.] +``` + +The client acknowledges the server's SYN/ACK, completing the TCP three-way handshake. + +--- + +### HTTP Request + +```text +23:56:10.219675 IP6 ::1.46764 > ::1.8080: Flags [P.] +``` + +Request line: + +```http +POST /notes HTTP/1.1 +``` + +Headers: + +```http +Host: localhost:8080 +User-Agent: curl/8.5.0 +Accept: */* +Content-Type: application/json +Content-Length: 39 +``` + +JSON request body: + +```json +{"title":"trace me","body":"in flight"} +``` + +The client sends a POST request to create a new note in QuickNotes. + +--- + +### HTTP Response + +```text +23:56:10.225582 IP6 ::1.8080 > ::1.46764: Flags [P.] +``` + +Response line: + +```http +HTTP/1.1 201 Created +``` + +Headers: + +```http +Content-Type: application/json +Date: Tue, 16 Jun 2026 20:56:10 GMT +Content-Length: 93 +``` + +Response body: + +```json +{"id":13,"title":"trace me","body":"in flight","created_at":"2026-06-16T20:56:10.22009407Z"} +``` + +The server successfully created the note and returned its details. + +--- + +### Connection Close + +Client initiates connection termination: + +```text +23:56:10.225771 IP6 ::1.46764 > ::1.8080: Flags [F.] +``` + +Server acknowledges and closes its side: + +```text +23:56:10.225826 IP6 ::1.8080 > ::1.46764: Flags [F.] +``` + +Final acknowledgement: + +```text +23:56:10.225840 IP6 ::1.46764 > ::1.8080: Flags [.] +``` + +This is a normal TCP connection shutdown using FIN packets. + +--- + +### Task 1.3: Debugging Commands Outputs + +#### 1. What is listening on port 8080? + +```bash +LISTEN 0 4096 *:8080 *:* users:(("quicknotes",pid=4490,fd=3)) +```` + +QuickNotes is actively listening for incoming TCP connections on port 8080. + +### 2. Routing Table + +```bash +default via 172.20.96.1 dev eth0 proto kernel +172.20.96.0/20 dev eth0 proto kernel scope link src 172.20.99.213 +``` + +The default route sends external traffic through the gateway 172.20.96.1 using interface eth0. + +#### 3. Reachability Test + +```bash +Start: 2026-06-16T23:59:48+0300 +HOST: GhadeerPC Loss% Snt Last Avg Best Wrst StDev + 1.|-- localhost 0.0% 5 0.0 0.1 0.0 0.2 0.1 +``` + +The localhost interface is reachable with zero packet loss and negligible latency. + +#### 4. DNS Resolution + +```bash +104.20.23.154 +172.66.147.243 +``` + +The DNS query successfully resolved example.com using Cloudflare's DNS server (1.1.1.1). + +#### 5. Journal Logs + +```bash +-- No entries -- +``` + +No user systemd service named quicknotes is currently installed or generating logs. + +--- + +### What would you check first if QuickNotes returned 502? + +A 502 Bad Gateway error usually indicates that a reverse proxy (such as Nginx, Traefik, or a load balancer) cannot successfully communicate with the backend application. The first thing I would check is whether QuickNotes is actually running and listening on port 8080 using `ss -tlnp`. If the service is running, I would inspect the application logs using `journalctl` and verify connectivity by sending a direct request with `curl http://localhost:8080`. Finally, I would review the reverse proxy configuration to ensure it is forwarding traffic to the correct backend address and port. + +--- + +## Task 2 + +### 2.1 Run a Broken Instance + +First instance: + +```bash +ADDR=:8080 go run . & +``` + +Output: + +```text +2026/06/17 00:22:13 quicknotes listening on :8080 (notes loaded: 13) +``` + +Verification: + +```bash +ss -tlnp | grep 8080 +``` + +Output: + +```text +LISTEN 0 4096 *:8080 *:* users:(("quicknotes",pid=4798,fd=3)) +``` + +Second instance: + +```bash +ADDR=:8080 go run . 2>&1 | tee /tmp/qn-broken.log & +``` + +Output: + +```text +2026/06/17 00:24:02 quicknotes listening on :8080 (notes loaded: 13) +2026/06/17 00:24:02 listen: listen tcp :8080: bind: address already in use +exit status 1 +``` + +Captured log: + +```bash +cat /tmp/qn-broken.log +``` + +Output: + +```text +2026/06/17 00:24:02 quicknotes listening on :8080 (notes loaded: 13) +2026/06/17 00:24:02 listen: listen tcp :8080: bind: address already in use +exit status 1 +``` + +The second QuickNotes instance failed because TCP port 8080 was already occupied by the first instance. + +--- + +### 2.2 Outside-In Debugging Chain + +#### Step 1 – Is it running? + +Command: + +```bash +ps -ef | grep quicknotes +``` + +Output: + +```text +g-akleh 4798 4756 0 00:22 pts/4 00:00:00 /home/g-akleh/.cache/go-build/9b/9bbbd37722f22fffcda19af5517656fc0a2a84b1503acf25c0c91e18e44b337b-d/quicknotes +g-akleh 4860 4623 0 00:26 pts/4 00:00:00 grep --color=auto quicknotes +``` + +Decision: + +A QuickNotes process is running, indicating that the service itself has not completely failed. + +--- + +#### Step 2 – Is it listening? + +Command: + +```bash +ss -tlnp | grep 8080 +``` + +Output: + +```text +LISTEN 0 4096 *:8080 *:* users:(("quicknotes",pid=4798,fd=3)) +``` + +Decision: + +QuickNotes is successfully listening on TCP port 8080. + +--- + +#### Step 3 – Is it reachable? + +Command: + +```bash +curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8080/health +``` + +Output: + +```text +200 +``` + +Decision: + +The application is reachable and responding successfully to requests. + +--- + +#### Step 4 – Is a firewall blocking access? + +Command: + +```bash +sudo iptables -L -n -v 2>/dev/null || sudo nft list ruleset 2>/dev/null || true +``` + +Output: + +```text +(no firewall rules affecting port 8080 were outputted) +``` + +Decision: + +There is no evidence that a firewall is preventing access to the service. I'm assuming this is because I'm using WSL. + +--- + +#### Step 5 – Does DNS work? + +Command: + +```bash +dig +short localhost +``` + +Output: + +```text +127.0.0.1 +``` + +Decision: + +DNS resolution is functioning correctly and localhost resolves to the local machine. + +--- + +### Root Cause Analysis + +Error outputted: + +```text +2026/06/17 00:24:02 listen: listen tcp :8080: bind: address already in use +exit status 1 +``` + +The debugging process showed that: + +- QuickNotes was already running. +- Port 8080 was already bound. +- The application was reachable. +- No firewall issues were present. +- DNS resolution was functioning normally. + +Therefore, the root cause was a port conflict: the second QuickNotes instance attempted to bind to port 8080 while it was already being used by the first instance. + +--- + +### 2.3 Repair and Re-Verification + +The conflicting instance was terminated: + +```bash +kill $PID1 +``` + +After restarting QuickNotes, the application was verified using: + +```bash +curl -s http://localhost:8080/health +``` + +Output: + +```json +{"notes":13,"status":"ok"} +``` + +Verification confirmed that the application was running normally and responding successfully after the conflicting process was removed. + +--- + +### Mini Postmortem + +This incident was caused by a port conflict rather than a problem in the application itself. The second QuickNotes instance tried to bind to TCP port 8080 while that port was already in use by another running process. Failures of this type are common during deployments, service restarts, local development, and configuration changes. The issue is that multiple processes were configured to use the same network resource without coordination. To reduce the possibility of this failure, teams can use service managers such as systemd, container orchestration platforms, startup validation checks, monitoring systems, and deployment automation that verifies port availability before launching a new instance. These controls help detect configuration conflicts before they impact users.