I am attempting to set up a server using pengines in prolog which loads facts from a file using the persistency library and then use a javascript client to make queries of the prolog server and am having a problem accessing the persisted facts from the pengine client.
My repository is linked here.
The server is run from prolog like so:
:- use_module(library(pengines)).
:- use_module(library(http/http_server)).
% Load your Prolog files
:- consult('ais_system.pl').
attach_db('facts.pl').
% Start the HTTP server on port 5000
server(Port) :-
http_server(http_dispatch, [port(Port)]),
format('Pengines server running at http://localhost:~d/~n', [Port]).
:- initialization(server(5000)).
And the client makes a request db:get_all_ais_ping(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,"Under way using engine",_,_,_,_,_,_,_,Matches)
using the javascript library.
I get the following response:
An error occurred: {
code: 'permission_error',
data: "No permission to call sandboxed `with_mutex(_3490,_3492)'\n" +
'Reachable from:\n' +
'\t db:get_all_ais_ping(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1)',
event: 'error',
id: 'bb84b48d-0095-4d40-8ea0-910c18a14e55',
...
}
I also noticed that in the swipl session if I run the command in the swipl session I get no Matches:
?- db:get_all_ais_ping(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,"Under w
ay using engine",_,_,_,_,_,_,_,Matches).
Matches = [].
?- findall(Match,
db:get_all_ais_ping(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,"Under way using engine",_,_,_,_,_,_,_,Match),
[MatchesList]),
length(MatchesList, Count).
MatchesList = [],
Count = 0.
However when I run them in swipl normally I get the Matches I expect:
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.12)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- ['ais_system.pl'].
true.
?- attach_db('facts.pl').
true.
?- db:get_all_ais_ping(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,"Under way using engine",_,_,_,_,_,_,_,Matches).
Matches = [ais_ping(_, _, _, "Unknown", _, "99.0", _, "AIS", "Unknown", _, _, "101", "Unknown", 55.6534, _, 10.4751, 538005558, _, "Under way using engine", "0.0", "Undefined", "12.6", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, _, _, "AIS", "Unknown", _, _, _, "Unknown", 55.94244, _, 11.866282, 219027804, _, "Under way using engine", _, "Undefined", "0.0", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "120.0", _, "AIS", "Unknown", _, _, "240", "Unknown", 55.001667, _, 8.341, 219573000, _, "Under way using engine", "0.0", "Undefined", "0.1", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "237.6", _, "AIS", "Unknown", _, _, "238", "Unknown", 55.614987, _, 15.477585, 423519100, _, "Under way using engine", "0.0", "Undefined", "11.1", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "219.2", _, "AIS", "Unknown", _, _, "219", "Unknown", 55.314413, _, 14.44054, 230351000, _, "Under way using engine", "0.0", "Undefined", "13.3", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "154.0", _, "AIS", "Unknown", _, _, "157", "Unknown", 55.322848, _, 13.156212, 209869000, _, "Under way using engine", "0.0", "Undefined", "13.5", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "56.9", _, "AIS", "Unknown", _, _, "56", "Unknown", 54.655555, _, 11.201777, 219472000, _, "Under way using engine", "0.0", "Undefined", "5.7", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "65.0", _, "AIS", "Unknown", _, _, "65", "Unknown", 55.45345, _, 14.8722, 566060000, _, "Under way using engine", "0.0", "Undefined", "18.1", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ...)|...].
?- findall(Match,
db:get_all_ais_ping(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,"Under way using engine",_,_,_,_,_,_,_,Match),
[MatchesList]),
length(MatchesList, Count).
MatchesList = [ais_ping(_, _, _, "Unknown", _, "99.0", _, "AIS", "Unknown", _, _, "101", "Unknown", 55.6534, _, 10.4751, 538005558, _, "Under way using engine", "0.0", "Undefined", "12.6", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, _, _, "AIS", "Unknown", _, _, _, "Unknown", 55.94244, _, 11.866282, 219027804, _, "Under way using engine", _, "Undefined", "0.0", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "120.0", _, "AIS", "Unknown", _, _, "240", "Unknown", 55.001667, _, 8.341, 219573000, _, "Under way using engine", "0.0", "Undefined", "0.1", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "237.6", _, "AIS", "Unknown", _, _, "238", "Unknown", 55.614987, _, 15.477585, 423519100, _, "Under way using engine", "0.0", "Undefined", "11.1", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "219.2", _, "AIS", "Unknown", _, _, "219", "Unknown", 55.314413, _, 14.44054, 230351000, _, "Under way using engine", "0.0", "Undefined", "13.3", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "154.0", _, "AIS", "Unknown", _, _, "157", "Unknown", 55.322848, _, 13.156212, 209869000, _, "Under way using engine", "0.0", "Undefined", "13.5", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "56.9", _, "AIS", "Unknown", _, _, "56", "Unknown", 54.655555, _, 11.201777, 219472000, _, "Under way using engine", "0.0", "Undefined", "5.7", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(_, _, _, "Unknown", _, "65.0", _, "AIS", "Unknown", _, _, "65", "Unknown", 55.45345, _, 14.8722, 566060000, _, "Under way using engine", "0.0", "Undefined", "18.1", "06/07/2024 00:00:00", "Class A", "Undefined", _), ais_ping(..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ..., ...)|...],
Count = 5826.
?-
@jan replied to my github issue about this with:
It says what it should say: with_mutex/2 is not allowed by the sandbox. That is correct as you can easily block things you should not be able or deadlock the system by misusing locks.
So, if you want to use this code, you’ll have to make sure it is safe and next declare the interface using the primitives of library(sandbox).
Could I ask for some tips about how I might go about making sure it is safe and declaring the interface using the privates of library(sandbox)?
Also, do you know why when I run the findall queries in the swipl session running the server I get no matches? Is this expected?