I built a micro web service but I find it hangs a lot. By hang I mean all requests will just time out, when it hangs, I can see the process is running fine in server using only about 15MB memory as usual. I think it's a very interesting problem to post, the code is super simple, please tell me what I am doing wrong.

```
app = Bottle()
# static routing
@app.route('/')
def server_static_home():
    return static_file('index.html', root='client/')

@app.route('/<filename>')
def server_static(filename):
    return static_file(filename, root='client/')

@app.get('/api/data')
def getData():
    data = {}
    arrayToReturn = []
    with open("data.txt", "r") as dataFile:
        entryArray = json.load(dataFile)
        for entry in entryArray:
            if not entry['deleted']:
                arrayToReturn.append(entry)
        data["array"] = arrayToReturn

    return data

@app.put('/api/data')
def changeEntry():

    jsonObj = request.json
    with open("data.txt", "r+") as dataFile:
        entryArray = json.load(dataFile)
        for entry in entryArray:
            if entry['id'] == jsonObj['id']:
                entry['val'] = jsonObj['val']
        dataFile.seek(0)
        json.dump(entryArray, dataFile, indent=4)
        dataFile.truncate()

    return {"success":True}

run_simple('0.0.0.0', 80, app, use_reloader=True)

```

Basically `mydomain.com` is route to my `index.html` and load necessary JS, CSS files, that's what static routing part is doing. Once page is loaded, an ajax `GET` request is fired to `/api/data` to load data and when I modify data, it fires another ajax `Put` request to `/api/data` to modify data.

**How to reproduce**

It's very easy to reproduce the hang, I just need to visit `mydomain.com` and refresh the page for 10-30 times rapidly, then it will stop responding. But I was never able to reproduce this locally how ever fast I refresh and `data.txt` is the same on my local machine. 

**Update**

Turns out it's not problem with read/write to file but a problem with trying to write to broken pipe. The client that sent request close the connection before receiving all the data. I'm looking into solution now...