1,792 questions
1
vote
1
answer
73
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 ...
1
vote
0
answers
113
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....
-3
votes
1
answer
115
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() {
...
3
votes
0
answers
153
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)
...
5
votes
1
answer
140
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"
...
-2
votes
1
answer
91
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 ...
1
vote
1
answer
59
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 := ...
1
vote
1
answer
64
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 ...
0
votes
1
answer
83
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....
1
vote
3
answers
330
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 ...
1
vote
1
answer
96
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 ...
0
votes
1
answer
161
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 ...
0
votes
2
answers
79
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 ...
-3
votes
3
answers
182
views
Functions look very similar. How to avoid code duplication?
I have a few convenience funcs and types in my utils package I use in several projects. They help me getting objects, array of objects from external apis via urls or custom requests (for auth api ...
0
votes
2
answers
151
views
Idiomatic way to share context to dynamically created subroutines [closed]
I'm currently working on go app that has few main components: api http server, another component (metrics http server) and amqp component. Basically, api receives info like "new queue X was ...