Skip to content

πŸ› Bug: Unreachable code after infinite loop + deprecated ioutil + TCP connection leakΒ #24

Description

@vietanhrs

Description

1. Unreachable code β€” mpping.go, bottom of main()

for {
    // ... infinite loop
}

<-c       // unreachable!
os.Exit(0) // unreachable!

The code after the infinite for loop can never execute. The signal handler in the goroutine already calls onStop() which exits.

2. TCP connection leak on read error β€” line ~213

poolConnection, err := net.Dial("tcp", ...)
// ...
fmt.Fprintf(poolConnection, request+"\n")
_, _ = bufio.NewReader(poolConnection).ReadString('\n')
// ...
poolConnection.Close()

If ReadString hangs or fails, there's no timeout on the connection. It will block forever. Use net.DialTimeout and conn.SetDeadline.

3. Deprecated ioutil usage pattern

While not directly used, the codebase follows old Go patterns.

4. strings.TrimLeft result discarded β€” line 63

strings.TrimLeft(urlArg, " ")

The result is never assigned back! Should be urlArg = strings.TrimLeft(urlArg, " ")

5. Division by zero possible β€” line 108

avgTime = poolList[poolID].TotalTime / poolList[poolID].TotalPacketsReceived

If TotalPacketsReceived is 0, this panics. The guard check exists but could be bypassed on first iteration.

File

mpping.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions