python3-driver icon indicating copy to clipboard operation
python3-driver copied to clipboard

`server.info.attached_databases` results in `InterfaceError`: 'Invalid response format'

Open daniel-heg opened this issue 3 months ago • 13 comments

Hi, first of all thank you for your work on FirebirdSQL.

I have a problem requesting information from a FirebirdSQL Server.

I am connected to a newly migrated server from FB v2.5 to 5.0.3, thus the switch fromfdb to firebird-driver.

In my previous code, I could use fdb’s server.get_attached_database_names() to get all the attached databases. Now, after updating the fbclient.dll to version 5.0.3 and switching to firebird-driver, I wanted to use the server.info.attached_databases. But this leads to the mentioned error: Invalid response format.

It does not seem to be a library configuration error, as I can request any other information (like server.info.architecture or server.info.engine_version) with the correct answer. I can also connect to any attached DB directly. That is also no problem. Just this call is not working. Am I doing something wrong? How can I debug this?

I have tried to change the encoding and charset of the server to see if it has to do something with the path names. However, there was no change.

I am on Windows x64 if that is of any help.

daniel-heg avatar Sep 12 '25 12:09 daniel-heg

That's certainly strange, as this information (obtained via info call with SrvInfoCode.SRV_DB_INFO code) is verified with driver test suite (see tests/test_info_providers.py function test_server_info_provider). I must admit that I run the test suite mostly only on Linux as it's my primary dev. platform, and there is no CI pipeline on github for this project to run it also on all other platforms.

Anyway, error Invalid response format is reported by InfoProvider._get_data in core.py when data block returned by server in result buffer does not end with isc_info_end tag. So, it's clearly malformed response from Windows Firebird server. What do you think @hvlad ?

The server.info.attached_databases is just wrapper that returns ServerInfoProvider.get_info(SrvInfoCode.SRV_DB_INFO)[1] which is the list of attached databases returned by get_info for this info code.

I will try to reproduce the error on Windows, as it works on Linux just fine with FB 5.0.3.

pcisar avatar Sep 12 '25 12:09 pcisar

@daniel-heg

wanted to use the server.info.attached_databases. But this leads to the mentioned error: Invalid response format.

Please save this script and run it as fllowing example: python C:\FBTESTING\qa\misc\srv_connect_test.py C:\FB\60SS\fbclient.dll (arg N1 = name of this script; arg N2 = full path to the client library of testing FB instance)

import os
import sys
import argparse as ap
import firebird.driver
from firebird.driver import driver_config, connect_server

parser = ap.ArgumentParser()
parser.add_argument("fb_clnt", help="Path to FB client library")
args = parser.parse_args()

assert os.path.isfile(args.fb_clnt), "FB client library not found: '%s'" % args.fb_clnt

# Register server
srv_cfg = """
    [test_srv]
    host = localhost
    user = SYSDBA
    password = masterkey
"""

driver_config.fb_client_library.value = args.fb_clnt
driver_config.register_server('test_srv', srv_cfg)

print('Python version:', sys.version.split()[0])
print(f'Driver package: {firebird.driver.__package__=}, {firebird.driver.__VERSION__=}')

with connect_server('test_srv', user='SYSDBA', password = 'masterkey') as srv:
    print(f'{srv.info.architecture=}')
    print(f'{srv.info.attached_databases=}')
    print(f'{srv.info.home_directory=}')
    print(f'{srv.info.version=}')
print('Done')
exit(0)

What it will show ?

PS.

On my machine output is:

Python version: 3.11.8
Driver package: firebird.driver.__package__='firebird.driver', firebird.driver.__VERSION__='2.0.2'
srv.info.architecture='Firebird/Windows/AMD/Intel/x64'
srv.info.attached_databases=[]
srv.info.home_directory='C:\\FB\\60SS\\'
srv.info.version='6.0.0.1266'
Done

If i do ISQL connection to employee than srv.info.attached_databases will be non-empty list.

pavel-zotov avatar Sep 12 '25 13:09 pavel-zotov

@pavel-zotov script works for me with current FB5

hvlad avatar Sep 12 '25 14:09 hvlad

Thanks for the swift replies.

@pavel-zotov

I get the following for my FB5 DB with the script from above:

Python version: 3.13.7
Driver package: firebird.driver.__package__='firebird.driver', firebird.driver.__VERSION__='2.0.2'
srv.info.architecture='Firebird/Windows/AMD/Intel/x64'
Traceback (most recent call last):
  File "██████████████████████████████████████\srv_connect_test.py", line 30, in <module>
    print(f'{srv.info.attached_databases=}')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "██████████████████████████████████████\.venv\Lib\site-packages\firebird\driver\core.py", line 4508, in attached_databases
    return self.get_info(SrvInfoCode.SRV_DB_INFO)[1]
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "██████████████████████████████████████\.venv\Lib\site-packages\firebird\driver\core.py", line 4402, in get_info
    self._get_data(request)
    ~~~~~~~~~~~~~~^^^^^^^^^
  File "██████████████████████████████████████\.venv\Lib\site-packages\firebird\driver\core.py", line 1141, in _get_data
    raise InterfaceError("Invalid response format")
firebird.driver.types.InterfaceError: Invalid response format

If I remove the line with the request for the attached databases:

Python version: 3.13.7
Driver package: firebird.driver.__package__='firebird.driver', firebird.driver.__VERSION__='2.0.2'
srv.info.architecture='Firebird/Windows/AMD/Intel/x64'
srv.info.home_directory='C:\\Program Files (x86)\\EVIDENT\\APPS\\FIREBIRD50\\'
srv.info.version='5.0.3.1683'
Done

Apologies if you wanted me to use one of the specific testing DBs. I am not sure where to find those.

daniel-heg avatar Sep 12 '25 15:09 daniel-heg

I wanted to make sure that it is not a Python version issue. I just retried with 3.11.8 and 3.12.11. The error still remains.

daniel-heg avatar Sep 12 '25 15:09 daniel-heg

srv.info.architecture='Firebird/Windows/AMD/Intel/x64' srv.info.home_directory='C:\Program Files (x86)\EVIDENT\APPS\FIREBIRD50\'

Looks like you have x64 binaries at the x86 folder, is it correct ?

hvlad avatar Sep 12 '25 15:09 hvlad

Or is it just x86 client with x64 server ? Then it is ok. Could you try with x64 client ?

hvlad avatar Sep 12 '25 15:09 hvlad

Looks like you have x64 binaries at the x86 folder, is it correct ?

Yes, that is sadly correct. As this is software installed by another company, I have no idea why this was done. I just have to make the connection work and rather not touch the FB installation otherwise.

Or is it just x86 client with x64 server ? Then it is ok.

It is the x64 server.

Could you try with x64 client ?

It is the x64 client also. The x86 client does not work as that raises a WinError in Python.

daniel-heg avatar Sep 12 '25 15:09 daniel-heg

Anyway, error Invalid response format is reported by InfoProvider._get_data in core.py when data block returned by server in result buffer does not end with isc_info_end tag. So, it's clearly malformed response from Windows Firebird server. What do you think @hvlad ?

isc_info_svc_svr_db_info returns the set of response items (isc_spb_num_att, isc_spb_num_db and zero or more isc_spb_dbname) finished by isc_info_flag_end (value 127) and I don't see where it is handled in core.py (ServerInfoProvider.get_info())

Also, values of isc_spb_num_att, isc_spb_num_db is read using read_short(), while it is 4-bytes values.

Finally, engine never consider as error when all requested response bytes exactly fits the user buffer and there is no space for final isc_info_end tag.

Perhaps I missed something, as I'm not a Python developer.

hvlad avatar Sep 12 '25 17:09 hvlad

So after some more digging, it seems that the call works after a fresh start of the Firebird Server for a while, but the error reappears again shortly after some reads / writes. So I don't think that this is a firebird-driver problem, but a Firebird Server one?

Is there a way in which I could output the raw response from the server?

daniel-heg avatar Sep 15 '25 13:09 daniel-heg

but the error reappears again shortly after some reads / writes

What actions were performed against server during this (short) time ? Did you change state of some database(s) to full shutdown or maybe these databases were replaced by restore ?

pavel-zotov avatar Sep 15 '25 14:09 pavel-zotov

What actions were performed against server during this (short) time ?

How can check this. Is there a possibility to trace the Server somehow?

Did you change state of some database(s) to full shutdown or maybe these databases were replaced by restore ?

I simply killed the fb_inet_server.exe via the Windows Task Manager. I do not know what happens with the DBs in that case. I am sorry.


I managed to print the different outputs from the Server as a byte string from python:

This is the one that results in Invalid response format:

b'2\x05\x15\x00\x00\x00\x06\x0b\x00\x00\x00j#\x00C:\\EVIDENT\\DATEN\\GLOBAL\\EHEALTH.FDBj"\x00C:\\EVIDENT\\DATEN\\GLOBAL\\GLOBAL.FDBj"\x00C:\\EVIDENT\\DATEN\\PRAXIS\\PRAXIS.FDBj"\x00C:\\EVIDENT\\DATEN\\QUELLE\\QUELLE.FDBj\x1d\x00C:\\EVIDENT\\DATEN\\TIS\\OTIS.FDBj&\x00C:\\EVIDENT\\DATEN\\TIS\\OTIS_TRANSFER.FDB\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

And this one which works, right after I kill FirebirdSQL:

b'2\x05\x05\x00\x00\x00\x06\x05\x00\x00\x00j"\x00C:\\EVIDENT\\DATEN\\GLOBAL\\GLOBAL.FDBj"\x00C:\\EVIDENT\\DATEN\\PRAXIS\\PRAXIS.FDBj\x1d\x00C:\\EVIDENT\\DATEN\\TIS\\OTIS.FDBj&\x00C:\\EVIDENT\\DATEN\\TIS\\OTIS_TRANSFER.FDBj\x1c\x00C:\\EVIDENT\\DATEN\\TIS\\TIS.FDB\x7f\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

Does this help?

daniel-heg avatar Sep 26 '25 08:09 daniel-heg

First response tells there are 21 attachments to the 11 databases, then it list databases names and after 6th name there is isc_info_truncated tag.

Second response tells there are 5 attachments to the 5 databases, then it list all 5 databases names, then isc_info_flag_end and isc_info_end tags.

Looks like driver doesnt handle isc_info_truncated tag correctly.

hvlad avatar Sep 26 '25 09:09 hvlad