Skip to content

[#139] Extra response data from global when due to incorrect $query termination

Sam Habiel requested to merge shabiel/YDB-Web-Server:mws139 into master

How to reproduce

gloreturn^%ydbwebapi uses a global reference as response data and can be used to demonstrate the problem.

  1. Start the web server: yottadb -run start^%ydbwebreq

  2. Run:

$ ydb -run ^%XCMD 'kill ^web set ^web("z")="WRONG DATA" zwr ^web'
^web("z")="WRONG DATA"
  1. Run:
~$ printf 'GET /test/gloreturn HTTP/1.1\r\n\r\n' | nc localhost 9080
HTTP/1.1 200 OK
Date: Fri, 01 Mar 2024 08:35:00 GMT
Content-Type: text/plain; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 15

coo
boo
foo
WRONG DATA

Diagnosis

The $query loop in src/_ydbwebrsp.m sent data after doing $query but before it checked that it finished with the global. The order is now reversed, and it it's now fixed. The code now has been made simpler, as it was trying to be stupidly bullet proof against conditions which cannot exist (like checking if the node returned by $query has a value... by definition, if $query returned it, it has a value).

Tests

  • gloreturn -> gloreturn1
  • gloreturn1 was previously disabled when we migrated the M-Web-Server to the YDB-Web-Server, as we didn't want to use globals. Since then, some use cases for globals encroached, and we have a framework for creating a temporary database file to use for globals.
  • gloreturn1 tests $query with a subscripted global, and makes sure that this issue is fixed.
  • gloreturn2 tests $query with an unsubscripted global.

Version bumped to 4.4.2 for a bug fix.

Merge request reports