blackbox_exporter icon indicating copy to clipboard operation
blackbox_exporter copied to clipboard

set SO_LINGER=0 to TCP connection

Open Sniper91 opened this issue 1 year ago • 2 comments

Closing TCP socket after every probe may cause large numbers of connections sitting in the TIME_WAIT state Relevant Issue: #794

set SO_LINGER=0 to avoid problem above Reference: https://stackoverflow.com/questions/3757289/when-is-tcp-option-so-linger-0-required

Sniper91 avatar Jul 18 '24 08:07 Sniper91

I tried to reproduce the situation reported in the issue and I couldn't. I don't see connections in the TIME_WAIT state. Would it be possible for you to provide more details as to how to reproduce this?

I'm hesitant to simply reset TCP connections from the client side instead of closing them in an orderly fashion.

mem avatar Jul 23 '24 17:07 mem

  1. run blackbox_exporter with file blackbox.yml version=0.25.0, branch=HEAD, revision=ef3ff4fef195333fb8ee0039fb487b2f5007908f
docker run -d  --rm   -p 9115:9115   --name blackbox_exporter   -v $(pwd):/config   quay.io/prometheus/blackbox-exporter:latest --config.file=/config/blackbox.yml
  1. run prometheus
docker run -d --network host --rm --name prometheus   -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

configuration file:

global:
  scrape_interval: 5s
scrape_configs:
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx] 
    static_configs:
      - targets:
          - https://prometheus.io
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115
  1. wait several minutes, check tcp connection state of blackbox_exporter container
  docker exec blackbox_exporter netstat -tnp
netstat

Sniper91 avatar Jul 24 '24 03:07 Sniper91

Hi 👋🏼, coming from the cleanup 🧹

This PR is quite old so I am going to close this, please feel free to reopen if you want to update it, and discuss it further.

electron0zero avatar Aug 01 '25 12:08 electron0zero