Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
22 stars 12 forks source link

[Bug] Fix `Cross-Origin Request Blocked` when starting the OC app with Docker #2279

Closed tschaffter closed 10 months ago

tschaffter commented 10 months ago

Is there an existing issue for this?

What product(s) are you seeing the problem on?

OpenChallenges

Current behavior

The error shown in the browser console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8082/api/v1/challengeAnalytics/challengesPerYear. (Reason: CORS request did not succeed). Status code: (null).

App config (.env):

API_DOCS_URL="http://localhost:8000/api-docs" 
APP_VERSION="1.0.0-alpha"
CSR_API_URL="http://localhost:8082/api/v1"
DATA_UPDATED_ON="2023-09-26"
ENVIRONMENT="production"
GOOGLE_TAG_MANAGER_ID=""
SSR_API_URL="http://openchallenges-api-gateway:8082/api/v1"

The same issue occurs when running the app with its dev server.

Expected behavior

No response

Anything else?

No response

Commit ID

9f1639c77cad695b43585ff68e1839b656fcda00

Are you developing inside the dev container?

Code of Conduct

tschaffter commented 10 months ago

The challenge service is not reachable on http://localhost:8085 but I can access the organization service.

UPDATE: The same issue arose when starting the challenge service with its dev server. I could fetch data from inside the dev container but not from the browser. I solved this issue by stopping VS Code from forwarding port 8085 and start forwarded again this port. The page localhost:8085 was then available in the browser.

There is an error in the logs of the challenge service:

2023-10-26 16:52:54 INFO  [http-nio-8085-exec-3] o.s.o.c.s.s.ChallengePlatformService - entitiesPage Page 2 of 14 containing org.sagebionetworks.openchallenges.challenge.service.model.entity.ChallengePlatformEntity instances
2023-10-26 16:56:02 ERROR [es_rest_client_sniffer[T#1]] o.elasticsearch.client.sniff.Sniffer - error while sniffing nodes
java.net.ConnectException: Connection refused
        at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:932)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:300)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288)
        at org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.sniff(ElasticsearchNodesSniffer.java:106)
        at org.elasticsearch.client.sniff.Sniffer.sniff(Sniffer.java:209)
        at org.elasticsearch.client.sniff.Sniffer$Task.run(Sniffer.java:140)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
        at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:174)
        at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:148)
        at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
        at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
        at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
        ... 1 common frames omitted
2023-10-26 16:56:03 INFO  [AsyncResolver-bootstrap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver - Resolving eureka endpoints via configuration
2023-10-26 17:01:02 ERROR [es_rest_client_sniffer[T#1]] o.elasticsearch.client.sniff.Sniffer - error while sniffing nodes
java.net.ConnectException: Connection refused
        at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:932)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:300)
        at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288)
        at org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.sniff(ElasticsearchNodesSniffer.java:106)
        at org.elasticsearch.client.sniff.Sniffer.sniff(Sniffer.java:209)
        at org.elasticsearch.client.sniff.Sniffer$Task.run(Sniffer.java:140)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
        at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:174)
        at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:148)
        at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
        at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
        at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
        ... 1 common frames omitted
2023-10-26 17:01:03 INFO  [AsyncResolver-bootstrap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver - Resolving eureka endpoints via configuration
tschaffter commented 10 months ago

Solution

The issue was that the API gateway (8082) port forwarding was not working. Same for the challenge service. In VS Code, I stopped forwarding these ports before forwarding them again. I restarted my computer to start from a clean slate in case this issue was affecting other ports. I can confirm that the app is working fine after re-forwarding these two ports.