Skip to content

Commit

Permalink
Bad async multipart fix; fixes #112 (#136)
Browse files Browse the repository at this point in the history
* Container waits for msbuild to finish now

* Async stream copying is awaited now, removing possibility of incomplete file streams on Linux

* Simple nginx compose configuration for testing

* Working port changed to 8088
  • Loading branch information
Alex Vorobiev authored Jun 16, 2020
1 parent 6ee488a commit b9acfac
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
7 changes: 4 additions & 3 deletions CDP4WebServices.API/Modules/10-25/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace CDP4WebServices.API.Modules
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

using CDP4Common.DTO;

Expand Down Expand Up @@ -832,7 +833,7 @@ private void PrepareMultiPartResponse(
}

// stream the multipart content to the request contents target stream
content.CopyToAsync(targetStream);
content.CopyToAsync(targetStream).Wait();
this.AddMultiPartMimeEndpoint(targetStream);
}

Expand Down Expand Up @@ -906,7 +907,7 @@ private void PrepareArchivedResponse(
content.Add(binaryContent);

// stream the multipart content to the request contents target stream
content.CopyToAsync(targetStream);
content.CopyToAsync(targetStream).Wait();

this.AddMultiPartMimeEndpoint(targetStream);
}
Expand Down Expand Up @@ -949,7 +950,7 @@ private void CreateFileResponseStream(Stream targetStream, string path)
var content = new ByteArrayContent(buffer);

// stream the multipart content to the request contents target stream
content.CopyToAsync(targetStream);
content.CopyToAsync(targetStream).Wait();
}

System.IO.File.Delete(path);
Expand Down
14 changes: 13 additions & 1 deletion compose.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ IF %1==devtest GOTO DevTest
IF %1==devtestbg GOTO DevTestBg
IF %1==devdown GOTO DevDown
IF %1==devtestdown GOTO DevTestDown
IF %1==nginx GOTO Serv
IF %1==nginxdown GOTO ServDown

GOTO End

:Serv
rem Need to build the application in Release before making the image
CALL MSBuild.exe CDP4-Server.sln -property:Configuration=Release -restore
START /B docker-compose -f docker-compose-nginx.yml up --build
GOTO End

:ServDown
START /B docker-compose -f docker-compose-nginx.yml down --remove-orphans
GOTO End

:Build
rem Need to build the application in Release before making the image
START /B MSBuild.exe CDP4-Server.sln -property:Configuration=Release -restore
CALL MSBuild.exe CDP4-Server.sln -property:Configuration=Release -restore
START /B docker-compose up --build
GOTO End

Expand Down
65 changes: 65 additions & 0 deletions docker-compose-nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: '3.8'
services:

cdp4_db:
image: rheagroup/cdp4-database-community-edition:latest
hostname: cdp4-postgresql
command: postgres -c max_locks_per_transaction=1024
environment:
- POSTGRES_PASSWORD=${DB_POSTGRESPASSWORD}
- POSTGRES_USER=postgres
networks:
cdp4:
aliases:
- cdp4-postgresql
container_name: cdp4-database-community-edition
restart: always
ports:
- '${DB_HOSTPORT}:5432'
expose:
- '5432'
volumes:
- cdpdbdata:/var/lib/postgresql/data
- cdpdblogs:/logs

cdp4_webservices:
hostname: cdp4-webservices
restart: always
build: .
networks:
cdp4:
aliases:
- cdp4-webservices
depends_on:
- cdp4_db
expose:
- '5000'
volumes:
- cdpwslogs:/app/logs
- cdpwsstorage:/app/storage
- cdpwsupload:/app/upload

nginx:
image: nginx:latest
container_name: cdp4-nginx
restart: always
depends_on:
- cdp4_webservices
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- 8088:80
networks:
cdp4:
aliases:
- cdp4-nginx

networks:
cdp4:

volumes:
cdpdbdata:
cdpdblogs:
cdpwslogs:
cdpwsstorage:
cdpwsupload:
15 changes: 15 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
events {

}

http {
error_log /etc/nginx/error_log.log warn;

server {
listen 80;

location / {
proxy_pass http://cdp4-webservices:5000;
}
}
}

0 comments on commit b9acfac

Please sign in to comment.