RobertIndie opened a new issue #61: URL: https://github.com/apache/apisix-java-plugin-runner/issues/61
### Issue description There are some issues when running the plugin in both Debug mode or Run mode. In debug mode, the sock file does not seem to be successfully shared between the host and the container. So we get the connection refused exception when creating a request. While in the run mode, it seems that the Java or the plugin file cannot be found by the apisix successfully in the container. ### Environment * your apisix-java-plugin-runner version :0.1 * host-machine system: macos bigsur ### Minimal test code / Steps to reproduce the issue * Followed the doc https://apisix.apache.org/docs/java-plugin-runner/development/ to implement a demo plugin * Then we can get the jar file `apisix-java-plugin-runner.jar` * Run the apache apisix according the doc: http://apisix.apache.org/docs/apisix/getting-started: ```sh # Download the Docker image of Apache APISIX git clone https://github.com/apache/apisix-docker.git # Switch the current directory to the apisix-docker/example path cd apisix-docker/example # Run the docker-compose command to install Apache APISIX docker-compose -p docker-apisix up -d ``` * Create a simple default route and add `ext-plugin-pre-req` plugin to that route. * Then we tested the plugin in debug mode and run mode. #### Run the plugin in the debug mode 1. Run the PluginRunnerApplication 2. Add some config in `apisix_conf/config.yml`: ```yaml ext-plugin: path_for_test: /tmp/runner.sock ``` 3. Add a volume to share the sock file between the host and the apisix container: ```yaml ... apisix: image: apache/apisix:2.6-alpine restart: always volumes: - ./apisix_log:/usr/local/apisix/logs - ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro - /tmp/runner.sock:/tmp/runner.sock ... ... ``` 4. Run curl to test the route, but we get the unexpected result: ```sh ➜ example git:(master) ✗ curl -i -X GET "http://localhost:9080/" -H "Host: example.com" HTTP/1.1 503 Service Temporarily Unavailable Date: Fri, 20 Aug 2021 12:51:29 GMT Content-Type: text/html; charset=utf-8 Content-Length: 194 Connection: keep-alive Server: APISIX/2.6 <html> <head><title>503 Service Temporarily Unavailable</title></head> <body> <center><h1>503 Service Temporarily Unavailable</h1></center> <hr><center>openresty</center> </body> </html> ``` 5. From the error.log file, we can see some log: ```sh 2021/08/20 13:02:23 [error] 47#47: *2374 connect() to unix:/tmp/runner.sock failed (111: Connection refused), client: 172.18.0.1, server: _, request: "GET / HTTP/1.1", host: "example.com" 2021/08/20 13:02:23 [error] 47#47: *2374 [lua] init.lua:536: phase_func(): failed to connect to the unix socket unix:/tmp/runner.sock: connection refused, client: 172.18.0.1, server: _, request: "GET / HTTP/1.1", host: "example.com" 2021/08/20 13:02:23 [warn] 47#47: *2374 [lua] plugin.lua:676: run_plugin(): ext-plugin-pre-req exits with http status code 503, client: 172.18.0.1, server: _, request: "GET / HTTP/1.1", host: "example.com" 2021/08/20 13:02:28 [error] 46#46: *2854 connect() to unix:/tmp/runner.sock failed (111: Connection refused), client: 172.18.0.1, server: _, request: "GET / HTTP/1.1", host: "example.com" 2021/08/20 13:02:28 [error] 46#46: *2854 [lua] init.lua:536: phase_func(): failed to connect to the unix socket unix:/tmp/runner.sock: connection refused, client: 172.18.0.1, server: _, request: "GET / HTTP/1.1", host: "example.com" 2021/08/20 13:02:28 [warn] 46#46: *2854 [lua] plugin.lua:676: run_plugin(): ext-plugin-pre-req exits with http status code 503, client: 172.18.0.1, server: _, request: "GET / HTTP/1.1", host: "example.com" ``` The `/tmp/runner.sock` file exists both in host and the apisix container: From the host: ```sh ➜ example git:(master) ✗ ll /tmp/runner.sock srwxr-xr-x 1 aaronrobert wheel 0B Aug 20 20:54 /tmp/runner.sock ➜ example git:(master) ✗ cat /tmp/runner.sock ➜ example git:(master) ✗ ``` From the container: ```sh /usr/local/apisix # ls -la /tmp/runner.sock srwxr-xr-x 1 root root 0 Aug 20 12:54 /tmp/runner.sock /usr/local/apisix # cat /tmp/runner.sock cat: can't open '/tmp/runner.sock': No such device or address ``` But the file in the container seems weird. #### Run the plugin in the run mode 1. Add some config in `apisix_conf/config.yml`: ```yaml ext-plugin: cmd: ['java', '-jar', '-Xmx4g', '-Xms4g', '/usr/local/apisix/test-plugin/apisix-java-plugin-runner.jar'] ``` 2. Mount the plugin file to the container: ```yaml apisix: image: apache/apisix:2.6-alpine restart: always volumes: - ./apisix_log:/usr/local/apisix/logs - ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro - /Users/xxx/codebase/apisix-java-plugin-runner/dist/apisix-runner-bin:/usr/local/apisix/test-plugin ``` 3. When running the apisix, it outputs some errors in the error.log: ```sh 2021/08/20 12:39:26 [warn] 52#52: *155 [lua] init.lua:617: respawning new runner..., context: ngx.timer 2021/08/20 12:39:26 [error] 52#241: lua pipe child execvpe() failed while executing java (2: No such file or directory) 2021/08/20 12:39:26 [warn] 52#52: *155 [lua] init.lua:607: runner exited with reason: exit, status: 1, context: ngx.timer 2021/08/20 12:39:26 [warn] 52#52: *155 [lua] init.lua:549: flush conf token lrucache, context: ngx.timer 2021/08/20 12:39:26 [warn] 52#52: *155 [lua] init.lua:615: respawn runner 3 seconds later with cmd: ["java","-jar","-Xmx4g","-Xms4g","\/usr\/local\/apisix\/test-plugin\/apisix-java-plugin-runner.jar"], context: ngx.timer ``` 4. The plugin jar file does exist in the container: ```sh /usr/local/apisix/test-plugin # ls -la /usr/local/apisix/test-plugin/apisix-java-plugin-runner.jar -rwxr-xr-x 1 root root 25681887 Aug 20 07:53 /usr/local/apisix/test-plugin/apisix-java-plugin-runner.jar /usr/local/apisix/test-plugin # java /bin/sh: java: not found ``` But it seems that java is not found. ### What's the actual result? (including assertion message & call stack if applicable) * Please see above for the assertion message. ### What's the expected result? * Return the HTTP response successfully. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
