influxdata / influxdb-client-php

InfluxDB (v2+) Client Library for PHP
https://influxdata.github.io/influxdb-client-php/
MIT License
150 stars 47 forks source link

fix: close the UdpWriter #144

Closed sokil closed 1 year ago

sokil commented 1 year ago

Proposed Changes

If UPD socket was previously closed by \InfluxDB2\UdpWriter::close and new write occured, error will be obtained socket_sendto(): Argument #1 ($socket) has already been closed

    $writeApi = $client->createUdpWriter();
    $writeApi->write("weather,location=Tokio temperature=$temp $seconds");
    $writeApi->close();
    $writeApi->write("weather,location=Tokio temperature=$temp $seconds"); // uses link to closed socket

This is because method close does not unset socket property:

    public function close()
    {
        if (isset($this->socket)) {
            socket_close($this->socket);
        }
    }

And getSocket does not create new connection because old still in socket property:

    protected function getSocket()
    {
        if (empty($this->socket)) {
            $this->socket = socket_create($this->getConfiguredInetVersion(), SOCK_DGRAM, SOL_UDP);
        }
        return $this->socket;
    }

Checklist

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage has no change and project coverage change: -0.07 :warning:

Comparison is base (5ff8234) 74.93% compared to head (123f1dd) 74.86%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #144 +/- ## ============================================ - Coverage 74.93% 74.86% -0.07% Complexity 424 424 ============================================ Files 25 25 Lines 1093 1094 +1 ============================================ Hits 819 819 - Misses 274 275 +1 ``` | [Impacted Files](https://app.codecov.io/gh/influxdata/influxdb-client-php/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) | Coverage Δ | | |---|---|---| | [src/InfluxDB2/UdpWriter.php](https://app.codecov.io/gh/influxdata/influxdb-client-php/pull/144?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata#diff-c3JjL0luZmx1eERCMi9VZHBXcml0ZXIucGhw) | `39.47% <0.00%> (-1.07%)` | :arrow_down: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

sokil commented 1 year ago

done

bednar commented 1 year ago

@sokil thanks again for PR 👍

sokil commented 1 year ago

Thank you for quick feedback!!