CollaboraOnline / richdocumentscode

Built-in CODE Server app
https://apps.nextcloud.com/apps/richdocumentscode
Apache License 2.0
121 stars 29 forks source link

Diagnostics code in proxy.php: bogus use of PHP function socket_last_error() #217

Closed rotdrop closed 1 year ago

rotdrop commented 1 year ago

The following cannot work:

https://github.com/CollaboraOnline/richdocumentscode/blob/12f5c2cc1d2cf2d68cd0a9ab912d1d5e79566e32/proxy.php#L395

When this line is hit, the typical error messages in the server log are:

[Fri Mar 24 12:57:53.124200 2023] [proxy_fcgi:error] [pid 2186073:tid 140417802696384] [client 2001:16b8:245b:201:a71:90ff:fe82:d0b6:57688] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught TypeError: socket_last_error(): Argument #1 ($socket) must be of type ?Socket, resource given in /var/www/dev1/htdocs/nextcloud-git-25/apps/richdocumentscode/proxy.php:395

and indeed we read in the PHP manual about $local = fsockopen(), see:

https://github.com/CollaboraOnline/richdocumentscode/blob/12f5c2cc1d2cf2d68cd0a9ab912d1d5e79566e32/proxy.php#L244

that it returns a file-pointer, while `socket_last_error()' expect an instance of the Socket class:

https://www.php.net/manual/de/function.fsockopen.php https://www.php.net/manual/en/function.socket-last-error

So the code in proxy.php would have to be changed to either not use socket_last_error(), or to not use fsockopen() and instead switch to the PHP Socket library.

This bug is in particular nasty for debugging, as it generates spurious secondary error messages when one would like to be able diagnose the real problem. This issues pops up also in the logs presented in other issues, e.g. in #202.