Skip to content

Commit

Permalink
remove closeChannelWhenEmpty busy loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Nov 7, 2024
1 parent b3853ac commit 94952cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ func CreateEngine(
)
}

pprofPortSpec, err := port_spec.NewPortSpec(6060, consts.EngineTransportProtocol, consts.HttpApplicationProtocol, defaultWait, consts.EmptyApplicationURL)

Check failure on line 172 in container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

mnd: Magic number: 6060, in <argument> detected (gomnd)
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred creating the pprofs http port spec object using number '%v' and protocol '%v'",
6060,

Check failure on line 177 in container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

mnd: Magic number: 6060, in <argument> detected (gomnd)
consts.EngineTransportProtocol.String(),
)
}

engineAttrs, err := objAttrsProvider.ForEngineServer(
engineGuid,
consts.KurtosisInternalContainerGrpcPortId,
Expand Down Expand Up @@ -205,11 +215,17 @@ func CreateEngine(
return nil, stacktrace.Propagate(err, "An error occurred transforming the Enclave Manager API port spec to a Docker port")
}

pprofDockerPort, err := shared_helpers.TransformPortSpecToDockerPort(pprofPortSpec)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred transforming the pprof port spec to a Docker port")
}

usedPorts := map[nat.Port]docker_manager.PortPublishSpec{
privateGrpcDockerPort: docker_manager.NewManualPublishingSpec(grpcPortNum),
enclaveManagerUIDockerPort: docker_manager.NewManualPublishingSpec(uint16(enclaveManagerUIPort)),
enclaveManagerAPIDockerPort: docker_manager.NewManualPublishingSpec(uint16(enclaveManagerAPIPort)),
restAPIDockerPort: docker_manager.NewManualPublishingSpec(engine.RESTAPIPortAddr),
pprofDockerPort: docker_manager.NewManualPublishingSpec(6060),

Check failure on line 228 in container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go

View workflow job for this annotation

GitHub Actions / golang-lint (container-engine-lib)

mnd: Magic number: 6060, in <argument> detected (gomnd)
}

// Configure the debug port only if it's required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ func (client *persistentVolumeLogsDatabaseClient) StreamUserServiceLogs(

// this go routine handles the stream cancellation
go func() {
//wait for stream go routine to end
// wait for stream go routine to end
wgSenders.Wait()

// send all buffered log lines
// flush should send remainder of logs in the channel
logLineSender.Flush()

// wait until the channel has been fully read/empty before closing it
closeChannelWhenEmpty(logsByKurtosisUserServiceUuidChan)
close(logsByKurtosisUserServiceUuidChan)
close(streamErrChan)

//then cancel the context
Expand Down Expand Up @@ -174,12 +173,3 @@ func (client *persistentVolumeLogsDatabaseClient) streamServiceLogLines(
shouldReturnAllLogs,
numLogLines)
}

func closeChannelWhenEmpty(logsChan chan map[service.ServiceUUID][]logline.LogLine) {
for {
if len(logsChan) == 0 {
close(logsChan)
return
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ func executeStreamCallAndGetReceivedServiceLogLines(
return nil, stacktrace.NewError("Receiving stream logs in the test has reached the '%v' time out", testTimeOut)
case streamErr, isChanOpen := <-errChan:
if !isChanOpen {
shouldReceiveStream = false
if len(userServiceLogsByUuidChan) == 0 {
shouldReceiveStream = false
}
break
}
return nil, stacktrace.Propagate(streamErr, "Receiving streaming error.")
Expand Down
32 changes: 20 additions & 12 deletions engine/server/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ package main
import (
"context"
"fmt"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/persistent_volume/file_layout"
"io/fs"
"math"
"net"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/engine/kurtosis_engine_rpc_api_bindings/kurtosis_engine_rpc_api_bindingsconnect"
enclaveApi "github.com/kurtosis-tech/kurtosis/api/golang/http_rest/server/core_rest_api"
Expand All @@ -39,6 +27,7 @@ import (
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/kurtosis_backend"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/persistent_volume"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/persistent_volume/file_layout"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/persistent_volume/log_file_manager"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/persistent_volume/logs_clock"
"github.com/kurtosis-tech/kurtosis/engine/server/engine/centralized_logs/client_implementations/persistent_volume/stream_logs_strategy"
Expand All @@ -57,6 +46,17 @@ import (
echomiddleware "github.com/labstack/echo/v4/middleware"
"github.com/rs/cors"
"github.com/sirupsen/logrus"
"io/fs"
"math"
"net"
"net/http"
_ "net/http/pprof"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -200,6 +200,14 @@ func runMain() error {
return stacktrace.Propagate(err, "Failed to create an enclave manager for backend type '%v' and config '%+v'", serverArgs.KurtosisBackendType, backendConfig)
}

// start server
go func() {
logrus.Info("Starting pprof server on :6060")
if err := http.ListenAndServe("0.0.0.0:6060", nil); err != nil {
logrus.Fatalf("pprof server failed: %v", err)
}
}()

go func() {
envJsFilePath := filepath.Join(pathToStaticFolder, envJsFilename)
envJsFilePathPerm := envJsFilePerm
Expand Down

0 comments on commit 94952cd

Please sign in to comment.