<!-- Love localstack? Please consider supporting our collective:
👉  https://opencollective.com/localstack/donate -->

# Type of request: This is a ...

[x] bug report
[ ] feature request

# Detailed description
When using persistence via DATA_DIR, after some use, localstack fails in initialise after a pod restart.
Log output with DEBUG=1
```

2021-05-12 22:25:27,962 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2021-05-12 22:25:27,968 INFO supervisord started with pid 14
2021-05-12 22:25:28,972 INFO spawned: 'dashboard' with pid 20
2021-05-12 22:25:28,975 INFO spawned: 'infra' with pid 21
2021-05-12 22:25:28,994 INFO success: dashboard entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2021-05-12 22:25:29,000 INFO exited: dashboard (exit status 0; expected)
(. .venv/bin/activate; exec bin/localstack start --host)
2021-05-12 22:25:30,002 INFO success: infra entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
Starting local dev environment. CTRL-C to quit.
Waiting for all LocalStack services to be ready

LocalStack version: 0.12.11
LocalStack build date: 2021-05-10
LocalStack build git hash: b320d70c

2021-05-12T22:25:36:DEBUG:bootstrap.py: Loading plugins - scope "services", module "localstack": <function register_localstack_plugins at 0x7f3363fd6160>
Starting edge router (https port 4566)...
Starting mock CloudWatch service on http port 4566 ...
[2021-05-12 22:25:37 +0000] [22] [INFO] Running on https://0.0.0.0:4566 (CTRL + C to quit)
2021-05-12T22:25:37:INFO:hypercorn.error: Running on https://0.0.0.0:4566 (CTRL + C to quit)
2021-05-12T22:25:37:INFO:localstack.multiserver: Starting multi API server process on port 33611
[2021-05-12 22:25:37 +0000] [22] [INFO] Running on http://0.0.0.0:33611 (CTRL + C to quit)
2021-05-12T22:25:37:INFO:hypercorn.error: Running on http://0.0.0.0:33611 (CTRL + C to quit)
Starting mock IAM service on http port 4566 ...
Starting mock STS service on http port 4566 ...
Starting mock Lambda service on http port 4566 ...
Starting mock CloudWatch Logs service on http port 4566 ...
Starting mock S3 service on http port 4566 ...
Starting mock SNS service on http port 4566 ...
Starting mock Cloudwatch Events service on http port 4566 ...
2021-05-12 22:25:38,463:API:  * Running on http://0.0.0.0:49993/ (Press CTRL+C to quit)
2021-05-12T22:25:38:DEBUG:localstack.services.awslambda.lambda_executors: Getting all lambda containers names.
2021-05-12T22:25:38:DEBUG:localstack.services.awslambda.lambda_executors: docker ps -a --filter="name=localstack_lambda_*" --format "{{.Names}}"
2021-05-12T22:25:38:DEBUG:localstack.services.awslambda.lambda_executors: Removing 0 containers.
2021-05-12T22:25:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:26:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:27:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:28:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:29:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:30:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:31:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:32:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:33:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:34:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:35:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:36:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:37:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:38:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
Waiting for all LocalStack services to be ready
2021-05-12T22:39:38:DEBUG:localstack.services.awslambda.lambda_executors: Checking if there are idle containers ...
Waiting for all LocalStack services to be ready

```

Environment(dind sidecar):

```
      - env:
        - name: SERVICES
          value: sns,s3,lambda,iam,sts,cloudwatch,cloudwatchlogs,cloudwatchevents,events
        - name: DATA_DIR
          value: /mnt/data
        - name: LAMBDA_EXECUTOR
          value: docker-reuse
        - name: LAMBDA_REMOTE_DOCKER
          value: "false"
        - name: DOCKER_HOST
          value: tcp://localhost:2376
        - name: DOCKER_TLS_VERIFY
          value: "1"
        - name: DOCKER_CERT_PATH
          value: /opt/docker/tls/client
        - name: PERSISTENCE_SINGLE_FILE
          value: "false"
        - name: DEBUG
          value: "1"

```

If I go deleting files in DATA_DIR, seems to be the S3 persistence file I need to delete in order to get the startup to progress.

Things happening on localstack before restart:

2 Lambda functions setup, 2 S3 buckets, an SNS and some S3 events and SNS events to kick off the Lambda functions.
...

## Expected behavior

That localstack can restart.
...

## Actual behavior

Localstack hangs indefinately
...

# Steps to reproduce

I may be able to share some terraform and boto commands later.

## Command used to start LocalStack

Docker 
...

## Client code (AWS SDK code snippet, or sequence of "awslocal" commands)

IAC: Terraform, Application: Boto

...

backend_env_name = '%s_BACKEND' % service_name.upper()
            backend_url = os.environ.get(backend_env_name, '').strip()
            if backend_url:
                endpoint_url = backend_url
        config = config or botocore.client.Config()
        
        if service_name == 's3':
            if re.match(r'https?://localhost(:[0-9]+)?', endpoint_url):
                endpoint_url = endpoint_url.replace('://localhost', '://%s' % get_s3_hostname())
        
        
        config.max_pool_connections = MAX_POOL_CONNECTIONS
        result = method(service_name, region_name=region,
            endpoint_url=endpoint_url, verify=verify, config=config, **kwargs)
        if not cache:
            return result
        BOTO_CLIENTS_CACHE[cache_key] = result
    return BOTO_CLIENTS_CACHE[cache_key]
def get_s3_hostname():
    global CACHE_S3_HOSTNAME_DNS_STATUS
    if CACHE_S3_HOSTNAME_DNS_STATUS is None:
        try:
            assert socket.gethostbyname(S3_VIRTUAL_HOSTNAME)
            CACHE_S3_HOSTNAME_DNS_STATUS = True
        except socket.error:
            CACHE_S3_HOSTNAME_DNS_STATUS = False
    if CACHE_S3_HOSTNAME_DNS_STATUS:
        return S3_VIRTUAL_HOSTNAME
    return LOCALHOST
def render_velocity_template(*args, **kwargs):