-
-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Environment:
- LDAP Server Type: OpenLDAP
- PHP Version: 8.3
Describe the bug:
We are using LdapRecord in a Laravel app. We have a running Queue Worker which processes jobs scheduled from within the application. Also, we currently use startTLS for the LDAP connection.
We found out that it can be problematic to use such a worker since it is one PHP process in an infinite while-loop. Therefore, other then for "normal" PHP apps, we don't have a new PHP process per job, and hence we stay with the same LDAP open connection for the whole process and at some point the LDAP complains about the connection since it has been open for too long.
As a workaround, we wanted to close all LDAP connections as soon as a job execution has finished, and assumed that the connection is then correctly re-established for the next job which is processed. We used $connection->disconnect()
for that purpose.
However, for subsequent jobs, we found out that startTLS is not anymore applied. As far as I see, the bind()
method uses startTLS()
only if ! $this->connection->isSecure()
. However, closing a connection does not reset the $secure
property of the connection (as it does for bound
, host
, protocol
, connection
).
Reconnecting this connection therefore does not do startTLS again.
So my assumption would be that this change in the close()
method might solve the problem:
public function close(): bool
{
$result = false;
if ($this->connection instanceof RawLdapConnection) {
$result = @ldap_close($this->connection);
}
$this->bound = false;
$this->host = null;
$this->protocol = null;
$this->connection = null;
+ $this->secure = false;
return $result;
}
But I'm not sure whether this might possibly yield some side effects. But generally, if a connection is closed, it should be assumed not to be secured anymore.
Thanks for taking a look at it and generally for the amazing work here!