Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package main
import (
"github.com/mittwald/mittnite/cmd"
log "github.com/sirupsen/logrus"
"os"
)

func init() {
Formatter := new(log.TextFormatter)
Formatter.TimestampFormat = "02-01-2006 15:04:05"
Formatter.FullTimestamp = true
log.SetFormatter(Formatter)
if os.Getenv("MITTNITE_LOG_LEVEL") == "debug" {
log.SetLevel(log.DebugLevel)
}
}

func main() {
Expand Down
23 changes: 17 additions & 6 deletions pkg/proc/job_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,34 @@ func (l *Listener) run(ctx context.Context) <-chan error {
fromUpstreamErrors := make(chan error)

go func() {
defer func() {
if tcpUpstream, ok := upstream.(*net.TCPConn); ok {
tcpUpstream.CloseWrite()
}
close(toUpstreamErrors)
}()

if _, err := io.Copy(upstream, conn); err != nil && !errors.Is(err, io.EOF) {
toUpstreamErrors <- err
}
close(toUpstreamErrors)
}()

go func() {
defer func() {
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.CloseWrite()
}
close(fromUpstreamErrors)
}()

if _, err := io.Copy(conn, upstream); err != nil && !errors.Is(err, io.EOF) {
fromUpstreamErrors <- err
}
close(fromUpstreamErrors)
}()

select {
case <-toUpstreamErrors:
case <-fromUpstreamErrors:
}
// wait for both channels (do not use `select-case`)
<-toUpstreamErrors
<-fromUpstreamErrors
}()
}
}()
Expand Down
2 changes: 2 additions & 0 deletions pkg/proc/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proc
import (
"context"
"fmt"
"runtime"
"sync"
"time"

Expand Down Expand Up @@ -104,6 +105,7 @@ func (r *Runner) Run() error {

// watch files
case <-ticker.C:
log.Debugf("active goroutines: %d", runtime.NumGoroutine())
for _, job := range r.jobs {
job.Watch()
if r.keepRunning {
Expand Down
Loading