aws-containers / eks-app-mesh-polyglot-demo

End to end deployment and observability of polyglot microservices in Amazon EKS using AWS App Mesh, AWS Fargate, Amazon Cloudwatch Container Insights, and AWS X-Ray
MIT No Attribution
64 stars 636 forks source link

App crashes/hangs when using space characters in product names and using EFS persistent storage #47

Open marvliet opened 1 month ago

marvliet commented 1 month ago

The problem is here: https://github.com/aws-containers/eks-app-mesh-polyglot-demo/blob/master/workshop/apps/product_catalog/app_efs.py

When using this app with EFS persistent storage, if you insert a new product into the product catalogue with a space character in the product name, then the app will break.

On line 137, the new product is written to the file on EFS: f.write('{} {}'.format(id, request.json['name'])) So if e.g. id = "121", and request.json['name'] contains "Brown shoes", the result written to file is "121 Brown shoes"

When reading from the storage, on line 71 it reads the contents of the file line by line with: (key, val) = line.split() But in Python, this will thrown and error if the line contains more than 2 values: "ValueError: too many values to unpack (expected 2)"

Seems that this error is not handled properly in the application and the application will crash/hang due to this.

One option is to replace:

(key, val) = line.split()

with:

(key, val) = line.split(" ",1)

To make sure it splits the line into exactly 2 parts. But I haven't verified if this causes any further problems upstream when val returned is "Brown shoes" (including a space). Hopefully someone has the time and interest to test & investigate this further?