Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "add timeouts to mysql and Kafka application discovery" #48

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 2 additions & 3 deletions cmd/scan.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
"net"
Expand Down Expand Up @@ -80,7 +79,7 @@ func scan(cmd *cobra.Command, args []string) error {
for _, target := range scanResults {
// Perform service discovery for open TCP ports
for _, port := range target.TCPPorts {
discoveryResult, err := ScanTargets(context.Background(), target.Host, port)
discoveryResult, err := ScanTargets(target.Host, port)
if err != nil {
fmt.Fprintf(os.Stderr, "Error while discovering services on %s:%d: %s\n", target.Host, port, err)
continue
Expand Down Expand Up @@ -112,7 +111,7 @@ func scan(cmd *cobra.Command, args []string) error {
}
// Perform service discovery for open UDP ports
for _, port := range target.UDPPorts {
discoveryResult, err := ScanTargets(context.Background(), target.Host, port)
discoveryResult, err := ScanTargets(target.Host, port)
if err != nil {
fmt.Fprintf(os.Stderr, "Error while discovering services on %s:%d: %s\n", target.Host, port, err)
continue
Expand Down
7 changes: 2 additions & 5 deletions cmd/servicediscovery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"io"
"sync"
Expand All @@ -22,7 +21,7 @@ type DiscoveryResult struct {
Properties map[string]interface{}
}

func ScanTargets(ctx context.Context, host string, port int) (result DiscoveryResult, err error) {
func ScanTargets(host string, port int) (result DiscoveryResult, err error) {
var sessionWg sync.WaitGroup
var presentationWg sync.WaitGroup
var applicationWg sync.WaitGroup
Expand Down Expand Up @@ -106,7 +105,6 @@ func ScanTargets(ctx context.Context, host string, port int) (result DiscoveryRe
if err != nil {
return
}

applicationLayerChan <- applicationDiscoveryResult
}(applicationDiscoveryItem)
}
Expand All @@ -127,11 +125,10 @@ func ScanTargets(ctx context.Context, host string, port int) (result DiscoveryRe
break // Stop checking application layer protocol
}
}

break // Stop checking presentation layer protocols
}

}

if presentationDiscoveryResult == nil || !presentationDiscoveryResult.GetIsDetected() {
// Continue to discover application layer protocols
applicationLayerChan := make(chan applicationLayerDiscoveryResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,19 @@ func (k *KafkaDiscovery) Discover(sessionHandler servicediscovery.ISessionHandle
// Configure the producer
config := sarama.NewConfig()
config.Producer.RequiredAcks = sarama.WaitForAll
// add a more strict connection timeout
config.Net.ReadTimeout = 10 * time.Second
config.Net.WriteTimeout = 10 * time.Second
config.Producer.Retry.Max = 1
config.Producer.Timeout = 500 * time.Millisecond
config.Producer.Return.Successes = true

// Create a new SyncProducer
producer, err := sarama.NewSyncProducer(brokerList, config)

if err != nil {
return &KafkaDiscoveryResult{
isDetected: false,
isAuthenticated: true,
properties: nil, // Set properties to nil as it's not used in this case
}, err
}

defer func() {
if err := producer.Close(); err != nil {
log.Debugf("Failed to close Kafka producer: %s", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package applicationlayerdiscovery

import (
"context"
"fmt"
"io"
"log"
"strings"
"time"

"database/sql"

Expand Down Expand Up @@ -57,10 +55,8 @@ func (d *MysqlDiscovery) Discover(sessionHandler servicediscovery.ISessionHandle
}, err
}

// Ping the server with passed context()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
err = db.PingContext(ctx)
// Ping the server
err = db.Ping()
if err != nil {
if strings.Contains(err.Error(), "Access denied") {
return &MysqlDiscoveryResult{
Expand Down
Loading