# 502 Bad Gateway

**URL:** <https://datashield.discourse.group/t/502-bad-gateway/791>\
**Category:** Beginner Support\
**Created:** [31 May 2023 17:36 UTC](https://datashield.discourse.group/t/502-bad-gateway/791 "2023-05-31T17:36:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [31 May 2023 17:36 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/1 "2023-05-31T17:36:26Z")

</div>

Hi, when I enter [https://srv1.fedana.cloud](https://srv1.fedana.cloud) in the browser, I get the error: “# 502 Bad Gateway — nginx/1.18.0”

The server worked fine a several weeks ago, docker processes look fine, nginx works fine, there is plenty of free memory. How do I fix this?

Kr, Wilmar

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [31 May 2023 18:34 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/2 "2023-05-31T18:34:31Z")

</div>

Hi,

Are you using opal or armadillo?

Is opal/armadillo application running?

Regards  
Yannick

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [31 May 2023 21:13 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/3 "2023-05-31T21:13:30Z")

</div>

OPAL, the whole DataSHIELD stack is running in docker containers using the yml file from the OPAL documentation (sort of).

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [1 June 2023 06:40 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/4 "2023-06-01T06:40:50Z")

</div>

Then the next question is: what do you have in the log file? (opal.log)

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [1 June 2023 09:04 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/5 "2023-06-01T09:04:10Z")

</div>

Dear Yannick,

I have decided to cut the Gordian knot by reinstalling the server following the tutorial [1], which takes about 30min. Works again!

Thanks, Wilmar

[1] [Federated Analysis with R/DataSHIELD – Installation, Data Import, Data Analysis [Tutorial] – Wilmar Igl, PhD](https://wilmarigl.de/?p=424)

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [1 June 2023 11:30 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/6 "2023-06-01T11:30:54Z")

</div>

@yannick Ok, it worked for while, but when I tried importing data, and I again got “502 Bad Gateway” error, when trying to login to OPAL on the website.

In additon, when trying to connect with opal.login() I get now the error: “Error: [Client error: (403) Forbidden]”

I guess, I have to go to the bottom of this. Where do I find opal.log when running datashield as a docker image?

Kr, Wilmar

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [2 June 2023 12:55 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/7 "2023-06-02T12:55:49Z")

</div>

@yannick I have found the opal.log, last lines (from FileUploadException):

ng,javax.ws.rs.core.UriInfo,javax.servlet.http.HttpServletRequest) throws java.io.IOException,org.apache.commons.fileupload.FileUploadException]  
2023-06-01 10:54:00,165 [qtp769896530-42] INFO org.obiba.opal.web.FilesResource - The following file was uploaded to Opal file system : file:///home/administrator/R/4488375/file4adc73071152.rds  
2023-06-01 10:54:00,170 [qtp769896530-42] INFO org.obiba.opal.core.service.security.realm.SpatialRealm - Clear cache perms for USER:administrator  
2023-06-01 10:54:13,443 [qtp769896530-163] WARN org.obiba.opal.spi.r.datasource.magma.RVariableHelper - Not a valid ‘opal.value\_type’ attribute value: character  
2023-06-01 10:54:13,492 [qtp769896530-163] INFO org.obiba.magma.support.AbstractValueTable - Entity batch size for c19vxcfs.am: 100000  
2023-06-01 10:54:13,655 [pool-15-thread-1] INFO org.obiba.opal.shell.service.impl.DefaultCommandJobService - Starting task 1  
2023-06-01 10:54:13,661 [pool-15-thread-1] INFO org.obiba.opal.core.service.ProjectsState - Project c19vxcfs to state BUSY  
2023-06-01 10:54:13,739 [pool-15-thread-1] INFO org.obiba.magma.support.DatasourceCopier - Copying ValueTable ‘c19vxcfs.am’ to ‘c19vxcfs.c19vxcfs.am’ (copyMetadata=true, copyValues=false).  
2023-06-01 10:55:20,967 [Index Synchronization Consumer org.obiba.opal.search.IndexSynchronizationManager$SyncConsumer@1653011a] INFO org.obiba.es.opal.support.ESIndexManager - Updating index mapping [opal-variables] for c19vxcfs\_\_c19vx  
cfs-am  
2023-06-01 10:55:21,116 [elasticsearch[Vague][clusterService#updateTask][T#1]] INFO org.elasticsearch.cluster.metadata - [Vague] [opal-variables] update\_mapping [Variable]  
2023-06-01 10:55:21,478 [elasticsearch[Vague][clusterService#updateTask][T#1]] INFO org.elasticsearch.cluster.metadata - [Vague] [opal-variables] update\_mapping [Variable]  
2023-06-01 10:57:18,303 [SessionValidationThread-1] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Validating all active sessions…  
2023-06-01 10:57:18,304 [SessionValidationThread-1] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Finished session validation. No sessions were stopped.

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [2 June 2023 14:20 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/8 "2023-06-02T14:20:02Z")

</div>

Ok, you need to troubleshoot a bit:

- I do not understand if the file was uploaded? FYI I generated a dataset same count of rows and columns as yours and it is only 8MB in RDS format (data are numbers) and it works. What kind of data do you have?

- The memory of the server does not tell how much is allocated to opal (default is 2G). You can check opal memory usage in Administration \> Java Virtual Machine. You can allocate more memory to opal using the [JAVA\_OPTS argument](https://opaldoc.obiba.org/en/latest/admin/installation.html#docker-image-installation)

- Have you checked the R server logs (that you can get from Administration \> R)? it may be informative

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [3 June 2023 05:50 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/9 "2023-06-03T05:50:57Z")

</div>

@yannickRescaled server from 4GB to 8GB RAM, Opal web works again, but still cannot import a file (1676488x2) with with object.size of 120 MB.

1. opal.table\_save() got stuck at 83% or fails with “Request entity too large”, file was uploaded with only 15,000 rows. Data object size is 120MB in R memory. Data had mixed 1x character and 1x numeric data (1000 rows works, 10000 rows works, 100000 rows works, but 1 000 000 rows fails, “Request entity too large”).

2. 

```
  - JAVA_OPTS=-Xms1G -Xmx8G -XX:+UseG1GC  

```

Seems alright for a server with 8GB RAM?

1. R logs & Opal log:

Download: [Nextcloud](https://wilmarigl.owncube.cloud/index.php/s/JAkes6Q24XHjfin)

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [3 June 2023 13:43 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/10 "2023-06-03T13:43:32Z")

</div>

Thanks for reporting these numbers; that will help.

1. If you allow opal to use **all** the memory of the server (8G) you’ll get into trouble when the R server (or any other process, like the database or even the system) needs some room!

2. The “Request entity too large” is probably coming from your nginx reverse proxy, see [Default nginx client\_max\_body\_size](https://stackoverflow.com/questions/28476643/default-nginx-client-max-body-size). Opal has a similar limit too, but it is 500M by default, which should be fine in your case.

This being said, given the size of the dataset and the context of usage being Datashield, you should use the “resource” approach instead: see [How to NOT Import Data](https://opaldoc.obiba.org/en/latest/cookbook/import-data/resources.html). You could, for instance, upload the prepared RDS (or TSV) file on the server at a location that is accessible by the R server, or you could upload it in a SQL database (mysql, postgresql). Then you declare in Opal how to connect to this data source, and Opal will just forward this information to R on [datashield.assign.resource](https://datashield.github.io/DSI/reference/datashield.assign.resource.html) request; the R server will then take care of the connection. This would keep the opal process memory usage to a minimum and reduce the data transfers.

Regards  
Yannick

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [7 June 2023 22:34 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/11 "2023-06-07T22:34:25Z")

</div>

Hi @yannick , I have exported the data as tibble frame to an RData file and moved it onto the server in the local docker filesystem (/home/dsuser/opal/fs/home/dsuser/data/\*.rda), and added a resource manually via OPAL GUI (category: local, Type: R Data file - local, Path: as above, R object class: tbl\_df).

On the client I can see the resource, but then I get errors:

> datashield.assign.resource(conns=connections, symbol = “rsam”, resource=“c19vxcfs.c19vxcfsam” )

Assigned all resource (rsam ← …) [==================================================] 100% / 1s

> datashield.assign.expr(conns=connections, symbol = “expam”, expr=quote(as.resource.data.frame(rsam, strict = TRUE)))

Assigned expr. (expam ← as.resource.data.frame(rsam, strict = TRUE)) [================] 100% / 0s Error: There are some DataSHIELD errors, list them with datashield.errors()

> datashield.errors()

$server1 [1] “Command ‘as.resource.data.frame(rsam, strict = TRUE)’ failed on ‘server1’: Error while evaluating ‘is.null(base::assign(‘expam’, value={resourcer::as.resource.data.frame(rsam, strict = TRUE)}))’ → Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection\n”

What is the problem?

Kr, Wilmar

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [9 June 2023 08:52 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/12 "2023-06-09T08:52:25Z")

</div>

Hi,

You have chosen to create a local file resource. This type of resource requires that the file be accessible by the **R server** (not opal). Considering that your R server is running in a Docker container, by default the files from the host are not accessible: a volume must be declared in the docker compose file to gain this access.

For instance:

```auto
        rock:
                image: datashield/rock-base:latest
                volumes:
                        - /some/host/path:/srv
                ...

```

In this example you will upload the file on the host at:

`/some/host/path/data/myfile.Rdata`

and you will declare the resource’s local path:

`/srv/data/myfile.Rdata`

Regards  
Yannick

---

<div class="post-metadata">

**Author:** ![wilmar.igl](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@wilmar.igl](https://datashield.discourse.group/u/wilmar.igl)\
**Post date:** [9 June 2023 10:40 UTC](https://datashield.discourse.group/t/502-bad-gateway/791/13 "2023-06-09T10:40:34Z")

</div>

Dear @yannick, thanks so much, works now! I have added the description of installilng and using “resources” to my tutorial at [Federated Analysis with R/DataSHIELD – Installation, Data Import, Data Analysis [Tutorial] – Wilmar Igl, PhD](https://wilmarigl.de/?p=424).

Kr, Wilmar
