piejanssens / sap-cf-socks

Apache License 2.0
2 stars 1 forks source link

VError: Found 0 matching services #1

Open wikingwei opened 2 years ago

wikingwei commented 2 years ago

Hi Pieter Janssens,

When using the latest code of sap-cf-socks, I got error as below, and don't know what's wrong. ( I checked my env var VCAP_SERVICES={ ..., "connectivity": [ ... ] } exists. )

   2022-01-14T18:50:52.72+0800 [APP/PROC/WEB/0] ERR (node:220) UnhandledPromiseRejectionWarning: VError: Found 0 matching services
   2022-01-14T18:50:52.72+0800 [APP/PROC/WEB/0] ERR     at Object.serviceCredentials (/xxxxx/node_modules/@sap/xsenv/lib/xsservices.js:116:11)
   2022-01-14T18:50:52.72+0800 [APP/PROC/WEB/0] ERR     at new ConnectivitySocks (/xxxxx/node_modules/sap-cf-socks/index.js:17:43)

   ...
   2022-01-14T18:50:52.72+0800 [APP/PROC/WEB/0] ERR (Use `node --trace-warnings ...` to show where the warning was created)
   2022-01-14T18:50:52.72+0800 [APP/PROC/WEB/0] ERR (node:220) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
   2022-01-14T18:50:52.72+0800 [APP/PROC/WEB/0] ERR (node:220) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And, I also tried using the old version (https://github.com/piejanssens/sap-cf-socks/blob/70c78f610431d824248a2a94146cb681056a1094/, embedded repo code directly into mine), but got other errors: 1) every 1 min, it reports error: write EPIPE

2022-01-10T17:21:25.75+0800 [APP/PROC/WEB/0] OUT Socket ended by BTP
   2022-01-10T17:21:25.75+0800 [APP/PROC/WEB/0] OUT Connection closed, reconnecting...
   2022-01-10T17:21:25.76+0800 [APP/PROC/WEB/0] OUT Socket connected
   2022-01-10T17:21:25.76+0800 [APP/PROC/WEB/0] OUT Socket connected
   2022-01-10T17:21:25.76+0800 [APP/PROC/WEB/0] OUT Socket ready
   2022-01-10T17:21:25.89+0800 [APP/PROC/WEB/0] OUT Socket error:  EPIPE
   2022-01-10T17:21:25.89+0800 [APP/PROC/WEB/0] ERR (node:95) UnhandledPromiseRejectionWarning: **Error: write EPIPE**
   2022-01-10T17:21:25.89+0800 [APP/PROC/WEB/0] ERR     at SocksClient.closeSocket (/xxxxx/node_modules/socks/build/client/socksclient.js:387:32)
   2022-01-10T17:21:25.89+0800 [APP/PROC/WEB/0] ERR     at SocksClient.onErrorHandler 

(/xxxxx/node_modules/socks/build/client/socksclient.js:360:14)
   2022-01-10T17:21:25.89+0800 [APP/PROC/WEB/0] ERR     at Socket.onError 
(/xxxxx/node_modules/socks/build/client/socksclient.js:222:38)

2) when do query DB, got errors like : a) error: getaddrinfo ENOTFOUND ... that's to say it cannot proxying to backend service; b) SocksClientError: Proxy connection timed out

Did someone get there errors? Could you help with this? Thanks, Wiking

piejanssens commented 2 years ago

Hi @wikingwei,

You should be able to put a breakpoint and debug the procedure of loading the VCAP_SERVICES to see what is going on.

Regarding the ENOTFOUND, I have seen that before, but only locally. Are you trying to run this locally (through a SSH tunnel) by any chance? Because that is not working (feel free to try, but I had to give up on that).

Best regards,

Pieter

wikingwei commented 2 years ago

@piejanssens, Thank you for your quick response.

To be clear for my runtime environment: I run my nodejs app using this sap-cf-socks lib in the CF runtime(standard plan), under my trial account of SAP BTP, with Connectivity service(lite plan).

1) For issue "VError: Found 0 matching services", now I solved it by changing to use xsenv generic function serviceCredentials(https://www.npmjs.com/package/@sap/xsenv ) as below, in my forked code //this.#connectivityCredentials = xsenv.cfServiceCredentials('connectivity') // the above cannot get node "connectivity" data in my BTP CF runtime, change to below then it works. this.#connectivityCredentials = xsenv.serviceCredentials({ tag: 'connectivity' });

2) For the ENOTFOUND, I did not run locally, and only run it in a docker in my BTP CF runtime, described as the above. And I have verified that my other services proxying using http/https protocol in my runtime is OK without ENOTFOUND issue (details: see my question description in SAP Community). By your suggestions, I will check further my runtime configurations for this TCP/Socks issue, and thank you very much :)

Best, Wiking

wikingwei commented 2 years ago

Using my forked and modified code, after solving the issue "VError: Found 0 matching services", now proxy authentication passed, but I got the following error:

 OUT SUCCESS: SOCKS5 authentication complete.
 OUT socks5 proxy auth response code success
 ERR events.js:377
 ERR       throw er; // Unhandled 'error' event
 ERR       ^
 ERR SocksClientError: Socks5 proxy rejected connection - NotAllowed
 ERR     at SocksClient.closeSocket (/xxxxxx/node_modules/socks/build/client/socksclient.js:387:32)
 ERR     at SocksClient.handleSocks5FinalHandshakeResponse(/xxxxxx/node_modules/socks/build/client/socksclient.js:633:18)
 ERR     at SocksClient.processData (/xxxxxx/node_modules/socks/build/client/socksclient.js:331:22)
 ERR     at SocksClient.onDataReceivedHandler (/xxxxxx/node_modules/socks/build/client/socksclient.js:304:14)
 ERR     at Socket.onDataReceived (/xxxxxx/node_modules/socks/build/client/socksclient.js:220:46)
 ERR     at Socket.emit (events.js:400:28)
 ERR     at Socket.emit (domain.js:475:12)
 ERR     at addChunk (internal/streams/readable.js:293:12)
 ERR     at readableAddChunk (internal/streams/readable.js:267:9)
 ERR     at Socket.Readable.push (internal/streams/readable.js:206:10)
 ERR     at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 ERR Emitted 'error' event on SocksClient instance at:
 ERR     at SocksClient.closeSocket (/xxxxxx/node_modules/socks/build/client/socksclient.js:387:18)
 ERR     at SocksClient.handleSocks5FinalHandshakeResponse(/xxxxxx/node_modules/socks/build/client/socksclient.js:633:18)
 ERR     [... lines matching original stack trace ...]
 ERR     at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
 ERR   options: {    proxy: {
 ERR       host: 'xxxx.xxxxx.xxxxx.ondemand.com',
 ERR       port: 20004,
 ERR       type: 5,
 ERR       custom_auth_method: 128,
 ERR       custom_auth_request_handler: [AsyncFunction: custom_auth_request_handler],
 ERR       custom_auth_response_size: 2,
 ERR       custom_auth_response_handler: [AsyncFunction: custom_auth_response_handler]

That's weird for this "NotAllowed" error, I did not get this error when I adopted the old version code((https://github.com/piejanssens/sap-cf-socks/blob/70c78f610431d824248a2a94146cb681056a1094)

Did someone see such an error? what causes it?

piejanssens commented 2 years ago

To be clear for my runtime environment: I run my nodejs app using this sap-cf-socks lib in the CF runtime(standard plan), under my trial account of SAP BTP, with Connectivity service(lite plan).

  1. For issue "VError: Found 0 matching services", now I solved it by changing to use xsenv generic function serviceCredentials(https://www.npmjs.com/package/@sap/xsenv ) as below, in my forked code //this.#connectivityCredentials = xsenv.cfServiceCredentials('connectivity') // the above cannot get node "connectivity" data in my BTP CF runtime, change to below then it works. this.#connectivityCredentials = xsenv.serviceCredentials({ tag: 'connectivity' });

I'll adopt using serviceCredentials instead of the CF specific cfServiceCredentials (strange that it doesn't work though.

Since the error seems to indicate a handshake/SOCKS authentication issue, at this point first thing to check is make sure it's sending the correct credentials in the handshake. Double check the binding and then follow this to attach a remote debugger (try to set a remote breakpoint and then restart the app).

wikingwei commented 2 years ago

Since the error seems to indicate a handshake/SOCKS authentication issue, at this point first thing to check is make sure it's sending the correct credentials in the handshake. Double check the binding and then follow this to attach a remote debugger (try to set a remote breakpoint and then restart the app).

Thanks very much for your suggestions, I've gotten started debugging following the guide.

T1mey commented 2 years ago

remote breakpoint and then restart the app).

You could change to

this.#connectivityCredentials = xsenv.cfServiceCredentials({ label: 'connectivity'})

This uses the label instead of the name which you can choose freely.

sreehari-pillai-atom commented 7 months ago

Changed to this.#connectivityCredentials = xsenv.serviceCredentials({ label : "connectivity" }) ;