apache / apisix-java-plugin-runner

APISIX Plugin Runner in Java
https://apisix.apache.org/
Apache License 2.0
128 stars 95 forks source link

request help: Follow apisix-java-plugin github to develop a plugin. Debug mode is OK, in deployment fails with "bind(..) failed: No such file or directory" #216

Closed zhlu001 closed 1 year ago

zhlu001 commented 1 year ago

Issue description

Follow java based plugin guide to try | develop plugin. In debug mode is OK. but engaged failure during deployment "io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: No such file or directory" https://github.com/tzssangglass/java-plugin-runner-demo-1

Environment

config.yaml as follow: deployment: role: traditional role_traditional: config_provider: etcd

etcd:

host:

- "http://192.168.65.134:2379"

admin: admin_key:

Trace the error.log Got exception: Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: No such file or directory I've checked steps carefully. still got above issue.

Any suggestions? Thanks in advance.

2022/11/25 02:46:42 [warn] 13720#13720: 177 [lua] init.lua:955: 2022-11-25 02:46:42.184 INFO 23260 --- [ main] c.e.d.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 11.0.2 on k8s3.com with PID 23260 (/usr/local/apisix/ext_plugins/demo-0.0.1-SNAPSHOT.jar started by root in /opt/projects/java-plugin-runner-demo-1-main/target) , context: ngx.timer 2022/11/25 02:46:42 [warn] 13720#13720: 177 [lua] init.lua:955: 2022-11-25 02:46:42.188 INFO 23260 --- [ main] c.e.d.DemoApplication : No active profile set, falling back to 1 default profile: "default" , context: ngx.timer 2022/11/25 02:46:42 [warn] 13720#13720: 177 [lua] init.lua:955: 2022-11-25 02:46:42.976 INFO 23260 --- [ main] c.e.d.DemoApplication : Started DemoApplication in 1.471 seconds (JVM running for 2.779) , context: ngx.timer 2022/11/25 02:46:45 [warn] 13720#13720: 177 [lua] init.lua:955: 2022-11-25 02:46:45.249 INFO 23260 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. , context: ngx.timer 2022/11/25 02:46:45 [warn] 13720#13720: *177 [lua] init.lua:955: 2022-11-25 02:46:45.267 ERROR 23260 --- [ main] o.s.b.SpringApplication : Application run failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:774) ~[spring-boot-2.7.1.jar!/:2.7.1] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:755) ~[spring-boot-2.7.1.jar!/:2.7.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.1.jar!/:2.7.1] at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:164) ~[spring-boot-2.7.1.jar!/:2.7.1] at com.example.demo.DemoApplication.main(DemoApplication.java:14) ~[classes!/:0.0.1-SNAPSHOT] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: No such file or directory

tzssangglass commented 1 year ago

same as: #137?

zhlu001 commented 1 year ago

same as: #137?

Almost same, it caused by apisix runtime will find "conf" sub-folder in current execution folder after attach to process debugging.
That means the actor has to execute "apisix start " under %APISIHOME% ( i.e. /usr/local/apisix ), otherwise, apisix runtime will find conf sub-folder. if "conf" folder doesn't exist. the error will popup.

therefore , recommend that

  1. no matter where "apisix start" executes, it automatically create sock file under static folder such as %APISIX_HOME%/conf
  2. add a mandatory configuration section for "ext-plugin" to let user set which folder to create sock file. thx
tzssangglass commented 1 year ago
  1. no matter where "apisix start" executes, it automatically create sock file under static folder such as %APISIX_HOME%/conf

I think APISIX already does this?

tzssangglass commented 1 year ago

That means the actor has to execute "apisix start " under %APISIHOME% ( i.e. /usr/local/apisix )

Does this mean that if you run apisix start in another folder, like /tmp, then a sock file will be created under /tmp/conf?

zhlu001 commented 1 year ago

No, config is not set for ext-plugin : path_to_test: /tmp/runner.sock (this mode is working). We set it as ext-plugin: cmd : ['jar','-jar','/path/to/runner.jar']

when execute "apisix start " while there is no conf folder in some folder, this error will popup. i.e. executed "apisx start" under /opt. apisix run time will find /opt/conf/apisix-{d}.sock. but definitionally, there is no conf folder. when execute "apisix start " under other-folder. apisix runtime will find other-folder/conf/apisix-{d}.sock.

you could repo this error but use above information. that's why we recommend that

  1. no matter where "apisix start" executes, it automatically create sock file under static folder such as %APISIX_HOME%/conf
  2. add a mandatory configuration section for "ext-plugin" to let user set which folder to create sock file. thx
tzssangglass commented 1 year ago
  1. it automatically create sock file under static folder such as %APISIX_HOME%/conf

I think we can do this: in APISIX ext-plugin, when creating a sock file, first check if the conf folder exists, and create it if it doesn't.

zhlu001 commented 1 year ago

Great, but it would be better to creating a sock file in a unified folder such %APISIX_Home%/conf. because user may run "apisix start" in any folder of system.

Thank you.