Repository: localstack/localstack

Issue:
Docker image 0.8.7: S3 not working as anymore?
We had been using `localstack/localstack:0.8.7` from last few months, but suddenly the tests started failing. I am able to reproduce the issue. 

**Docker compose:**
```
  localstack:
    image: localstack/localstack:0.8.7
    ports:
      - "8081:8080"
      - "80:80"
    networks:
      skynet:
        aliases:
          - localstack
    environment:
      SERVICES: s3:80
      DATA_DIR: /tmp/localstack/data
      DEBUG: 1
```

On curl I am able to create, get and delete buckets as `curl -XPUT localhost:80/bigbrownfox` etc. Similar logs are present in docker container for localstack

However following test code using S3 client(software.amazon.awssdk.services.s3.S3Client) is failing:-

**Kotlin code**
```
private val region = Region.US_EAST_1
private val s3 = S3Client.builder()
    .endpointOverride(URI("http://localhost:80"))
    .region(region)
    .credentialsProvider(StaticCredentialsProvider.create(AwsCredentials.create("foo", "bar")))
    .build()
val BUCKET_NAME = "bigbrownfox"

private fun bucketExists(): Boolean {
    return s3.listBuckets().buckets().count { bucket -> bucket.name() == BUCKET_NAME } == 1
}

fun createBucket() {
    val createBucketRequest = CreateBucketRequest.builder()
        .bucket(BUCKET_NAME)
        .createBucketConfiguration(CreateBucketConfiguration.builder()
            .locationConstraint(region.value())
            .build())
        .build()
//EXCEPTION HERE!!
    s3.createBucket(createBucketRequest)
}

fun main(args: Array<String>) {
    println("EXIST-> ${bucketExists()}")
    createBucket()
}
```
1. `bucketExists()` is working but `createBucket()` is giving exception:-

```
Exception in thread "main" software.amazon.awssdk.core.exception.SdkClientException: Unable to execute HTTP request: The target server failed to respond
```
2. In the docker logs there is no `PUT` request logged, so either the request at localstack had a crash before it could log or S3 client never sent it. Given that S3 client is expecting a reply, it seems to be the first case.

3. The issue is correlated to the latest update on tag `0.8.7`



Discussion:
Update: Its working in 0.8.6!
we also experience the same problem in our builds and also switched back to 0.8.6.
Same here. Switched back to 0.8.6
Thanks for reporting @mangatmodi @FrancescoFerro . Can you please confirm - does this problem still persist with the latest version on `master`?
This definitely still happens in 0.9.1.  I've tested this running Localstack on a Mac with the lates Python 3 in Homebrew (3.7.2_2) and running against Python 2.7 on a Linux Mint 19.1 distribution.  In both cases we are using the Java AWS SDK (v1.11.284) - with code that works fine against standard AWS services - and seeing "Caused by: org.apache.http.NoHttpResponseException: The target server failed to respond".

The configuration in Localstack is two S3 buckets, two SQS queues, and a policy on each bucket directing all PutObject requests be directed to its respective queue.  "The target server failed to respond" occurs in response to both SQS queue polling and S3 multipart upload API requests.
I'm also seeing this error with the latest Docker image. It seems to have something to do with multiple requests happening in parallel. When multiple threads write to S3 at once, the error sometimes occurs, but when it's limited to 1 thread at a time the error is gone. I made a minimal project to demonstrate the issue: https://github.com/rotoclone/localstack-error

Unfortunately there doesn't seem to be a way to specify the image version for the JUnit runner, so I can't just use 0.8.6 until this is fixed.

Resolving patch:
diff --git a/localstack/services/generic_proxy.py b/localstack/services/generic_proxy.py
--- a/localstack/services/generic_proxy.py
+++ b/localstack/services/generic_proxy.py
@@ -281,7 +281,6 @@ def forward(self, method):
                     print('ERROR: %s' % error_msg)
             self.send_response(502)  # bad gateway
             self.end_headers()
-        finally:
             # force close connection
             self.close_connection = 1
 


Test patch:
diff --git a/tests/integration/test_lambda.py b/tests/integration/test_lambda.py
--- a/tests/integration/test_lambda.py
+++ b/tests/integration/test_lambda.py
@@ -4,6 +4,7 @@
 import time
 import unittest
 from io import BytesIO
+from requests.models import Response
 from localstack import config
 from localstack.constants import LOCALSTACK_ROOT_FOLDER, LOCALSTACK_MAVEN_VERSION
 from localstack.utils import testutil
@@ -85,6 +86,10 @@ def test_forward_to_fallback_url_http(self):
         class MyUpdateListener(ProxyListener):
             def forward_request(self, method, path, data, headers):
                 records.append(data)
+                response = Response()
+                response.status_code = 200
+                response._content = ''
+                return response
 
         records = []
         local_port = get_free_tcp_port()