devture/matrix-corporal

ConsultREST API not connecting to REST API

Reis-A opened this issue · 5 comments

I installed matrix-corporal in a docker container and it is working alright.
Homeserver is installed on docker host and accessible via local ip and port.

I wanted to use the REST API Hook and installed a minimum REST API with flask on the docker host. The API is running and it reacts to curl get requests curl -Xget http://local-ip:5000/restapi

from the docker host as well as inside the matrix-corporal container when i use curl.

However, the ConsultRestAPI that i setup in the policy file never connects to the API on local-ip:5000. There is not even a request that arrives at the flask api.
What am I doing wrong? or why does the http module from go not connect..?

You need to run both containers on the same
container network and point corporal
to the name and port of the other container, not to localhost

ok. I was trying this in multiple ways without success. Finally I thought, let's try the development system.
so i cloned the repo to /root/gitclone/matrix-corporal
then make services-start
then copied the matrix-corporal config and policy files
then edited the policy file and put the name of the hook-rest machine in there in the preconfigured
hook http://matgrix-corporal_hook-rest-service_1:8080/dump
then make run-in-container-quick
then i login withuser a and try to create an unencrypted room
and then i get the same error:

DEBU[0029] Preserved 62 bytes of request payload so the hook can use it  handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
DEBU[0029] Hook execution result: hook.ExecutionResult{Hooks:[]*hook.Hook(nil), ResponseSent:false, SkipNextHooksInChain:false, ProcessingError:error(nil), ReverseProxyResponseModifiers:[]hook.HttpResponseModifierFunc{(hook.HttpResponseModifierFunc)(0x6ae5a0)}}  handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
DEBU[0029] HTTP gateway (policy-checked): proxying (with response modification)  handler=room.create method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
DEBU[0029] In after-hook response modifier               handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
DEBU[0029] Restored 62 bytes of request payload so the hook can use it  handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
DEBU[0029] RESTServiceConsultor: making HTTP request     RESTRequestAttempt=1 RESTRrequestMethod=POST RESTRrequestURL="http://matrix-corporal_hook-rest-service_1:8080/dump" handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
WARN[0029] RESTServiceConsultor: failed: Error fetching from URL: Post "http://matrix-corporal_hook-rest-service_1:8080/dump": context canceled**  RESTRequestAttempt=1 RESTRrequestMethod=POST RESTRrequestURL="http://matrix-corporal_hook-rest-service_1:8080/dump" handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
WARN[0029] RESTServiceConsultor: ultimately failed: Error fetching from URL: Post "http://matrix-corporal_hook-rest-service_1:8080/dump": context canceled  RESTRequestAttempt=1 RESTRrequestMethod=POST RESTRrequestURL="http://matrix-corporal_hook-rest-service_1:8080/dump" handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
DEBU[0029] After-hook execution result: hook.ExecutionResult{Hooks:[]*hook.Hook{(*hook.Hook)(0xc0000eae10)}, ResponseSent:false, SkipNextHooksInChain:true, ProcessingError:(*errors.errorString)(0xc00037a1f0), ReverseProxyResponseModifiers:[]hook.HttpResponseModifierFunc(nil)}  handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"
ERRO[0029] After-hook HTTP modifier response: error      error="Failed after trying 1 times. Last error: Error fetching from URL: Post \"http://matrix-corporal_hook-rest-service_1:8080/dump\": context canceled" handler=room.create hookChain="#log-everything-via-a-rest-hook" hookEventType=afterAnyRequest hookId=log-everything-via-a-rest-hook method=POST uri=/_matrix/client/r0/createRoom userId="@a:matrix-corporal.127.0.0.1.nip.io"

So I assume this is a general problem and not a problem of my particular setup.
It would be greatly appreciated if you could check, if you experience the same behavior.

ok. so installed matrix-corporal 2.3.2 before October 2022 when the file rest-service.go got updated.
and there the hook system works. so it is definitely a bug somewhere from transitioning from 2.3.2 to 2.40 where some changes where made in the handling of the context in go.
Since I have no clue about go, I cannot be of any help here :)

Reis-A commented

My problem with the ConsultREST API still persists.
I did some more tests in the development system I know now, that all works if the code in the file /corporal/hooks/rest_service_consulting.go in line 262 from
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration) defer cancel()
back to (from matrix-corporal 2.3.2)
ctx, _ := context.WithTimeout(context.Background(), timeoutDuration)

I don't really know the difference in the code and what the problem is with the new code... or maybe it is my setup?
but as i said i am using the development environment here...

The same problem arises. Rest service used self-descriptive and hook-rest-service in containers with the same network. The matrix-corporal image is used with https://hub.docker.com/r/devture/matrix-corporal.