1,794 questions
Score of 1
1 answer
149 views
Goroutines leaking after context cancellation in fan-out/fan-in worker pool
I have a fan-out/fan-in worker pool that's supposed to stop all workers when the context is cancelled, but under heavy load with short timeouts, the goroutine count keeps climbing and never recovers.
...
Advice
0
votes
5
replies
170
views
How can I safely implement a progress bar in a concurrent Go port scanner?
I wrote an open port scanner in Go. For local adresses scans are instant. However, when I scan an external address it takes a bit longer, and I want to see the progress. I tried to implement a ...
Score of 1
1 answer
156 views
Accessing postgres db using pgxpool in a goroutine
I have created a function to return the db connection of a postgresdb using pgxpool. But I don't want to create multiple pools since i will be calling this function each time to execute a query.
Since ...
Score of 1
0 answers
137 views
Golang benchmarks involving goroutines show higher than expected allocations when controlling the timer manually
Using go version go1.25.3 darwin/arm64.
The below implementation is a simplified version of the actual implementation.
type WaitObject struct{ c chan struct{} }
func StartNewTestObject(d time....
Score of -3
1 answer
120 views
Go routine is not blocking on unbuffered channel consumer [closed]
I created a single producer go routine which emits a value at random interval in an infinite for-loop, similar to this:
func producer() <-chan uint64 {
out := make(chan uint64)
go func() {
...
Score of 3
0 answers
173 views
How to immediately stop `io.Copy(os.Stdin, stream)` when stream is closed in Go?
I’m trying to forward input from os.Stdin to a network stream in Go like this:
go func() {
for {
if _, err := io.Copy(stream, os.Stdin); err != nil {
log.Error(err)
...
Score of 5
1 answer
162 views
How to overcome goroutine overhead?
I quite new to go. I need some help.
I guess I am facing a goroutine overhead. I was wondering if I can overcome the go-routine overhead. Here is my code.
package main
import (
"log"
...
Score of -2
1 answer
100 views
How to allow admin to cancel a long-running MQTT device activation in Go when using unbuffered channels? [closed]
I’m building a Go backend to control IoT motors via MQTT. Each device activation is handled asynchronously by a goroutine. Here’s the simplified flow:
A client POSTs /activate-device with device_id ...
Score of 1
1 answer
63 views
Channel of numerical values gives unexpected output with range <-myChan
The following code produces an unexpected runtime error:
package main
import (
"fmt"
"sync"
)
func receiver(bChan <-chan int, wg *sync.WaitGroup) {
for val := ...
Score of 1
1 answer
72 views
Correct pattern to process ZeroMQ messages using Goroutines
I am implementing a Zero MQ message listener service in Go, and I am struggling to find the most idiomatic pattern of processing those messages and storing them in a DB using Goroutines. I am ...
Score of 0
1 answer
119 views
Are these goroutines any leaks at all?
For example, given this code, which I am reviewing right now, (pardon me the simplification a bit, but it should convey the gist):
ctx, cancel := context.WithCancel(ctx)
sigCh := make(chan os....
Score of 1
3 answers
421 views
Golang http.Client causes increasing goroutines and (socket) file descriptors
I have a Go program that runs continuously, and I've noticed that both the number of goroutines and open file descriptors increase steadily over time (daily). However, the number of active network ...
Score of 1
1 answer
101 views
why I am not getting deadlock
I was revising the concepts of the channels in go where I learned in the unbuffered channel if the receivers are less but senders are more then It must give deadlock and vice versa
In my case first ...
Score of 0
1 answer
190 views
increasing number of goroutines when using go-co-op/gocron
I'm trying to create some cron tasks to test out the https://github.com/go-co-op/gocron library. I'm exploring the singleton mode where if the same instance of a task is being executed, then it's ...
Score of 0
2 answers
86 views
How to build a circular pipeline?
Let's say I have a function F with the following logic:
a <- input
output <- a+10
b <- input
output a+b
stop
Now I want to build two blocks (A and B) that implement this logic, each feeding ...