2023-03-05 08:48:43 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<link
|
|
|
|
rel="stylesheet"
|
|
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown-dark.min.css"
|
|
|
|
/>
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
|
|
<link
|
|
|
|
href="https://fonts.googleapis.com/css2?family=Inter&family=JetBrains+Mono&family=Martian+Mono&family=Recursive&display=swap"
|
|
|
|
rel="stylesheet"
|
|
|
|
/>
|
2023-04-01 03:37:48 +00:00
|
|
|
<title>haunt98 posts</title>
|
2023-03-05 08:48:43 +00:00
|
|
|
</head>
|
|
|
|
<style>
|
|
|
|
.markdown-body {
|
|
|
|
box-sizing: border-box;
|
|
|
|
min-width: 200px;
|
|
|
|
max-width: 980px;
|
|
|
|
margin: 0 auto;
|
|
|
|
padding: 45px;
|
|
|
|
}
|
|
|
|
|
|
|
|
@media (max-width: 767px) {
|
|
|
|
.markdown-body {
|
|
|
|
padding: 15px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.markdown-body {
|
2023-03-31 10:24:36 +00:00
|
|
|
font-family: "Inter", sans-serif;
|
|
|
|
<!-- font-family: "Recursive", sans-serif; -->
|
2023-03-05 08:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.markdown-body code,
|
|
|
|
.markdown-body pre {
|
2023-03-31 10:24:36 +00:00
|
|
|
font-family: "JetBrains Mono", monospace;
|
|
|
|
<!-- font-family: "Martian Mono", monospace; -->
|
2023-03-05 08:48:43 +00:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<body class="markdown-body">
|
2023-04-19 08:56:12 +00:00
|
|
|
<div><a href="index.html">Index</a></div>
|
2023-03-05 08:48:43 +00:00
|
|
|
<h1>
|
|
|
|
<a
|
|
|
|
id="user-content-incident-come-and-go"
|
|
|
|
class="anchor"
|
|
|
|
aria-hidden="true"
|
|
|
|
href="#incident-come-and-go"
|
|
|
|
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
|
|
|
>Incident come and go
|
|
|
|
</h1>
|
|
|
|
<p>This is collect of all incidents I created in the past :(</p>
|
|
|
|
<h2>
|
|
|
|
<a
|
|
|
|
id="user-content-service-starts-with-empty-port"
|
|
|
|
class="anchor"
|
|
|
|
aria-hidden="true"
|
|
|
|
href="#service-starts-with-empty-port"
|
|
|
|
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
|
|
|
>Service starts with empty port
|
|
|
|
</h2>
|
|
|
|
<p>Because all configs is read from file.</p>
|
|
|
|
<p>
|
|
|
|
But the port config is empty -> So when service inits, it use that
|
|
|
|
empty port somehow.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<strong>Solution</strong>: For some configs, make sure to failed first if
|
|
|
|
it's empty.
|
|
|
|
</p>
|
2023-04-09 04:53:17 +00:00
|
|
|
<h2>
|
|
|
|
<a
|
|
|
|
id="user-content-race-condition-of-series-of-apis"
|
|
|
|
class="anchor"
|
|
|
|
aria-hidden="true"
|
|
|
|
href="#race-condition-of-series-of-apis"
|
|
|
|
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
|
|
|
>Race condition of series of APIs
|
|
|
|
</h2>
|
|
|
|
<p>For example I have 2 APIs:</p>
|
|
|
|
<ul>
|
|
|
|
<li>API upload: allow user to upload image</li>
|
|
|
|
<li>API submit: submit data to server</li>
|
|
|
|
</ul>
|
|
|
|
<p>
|
|
|
|
API upload is slow, it takes 10s to finish. API submit is fast, only takes
|
|
|
|
2s.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The problem is submit use data from upload too. When user calls API
|
|
|
|
upload, image is stored in cache. When user calls API submit, it use
|
|
|
|
whatever image is stored in cache.
|
|
|
|
</p>
|
|
|
|
<p>It's when the fun begins.</p>
|
|
|
|
<p>
|
|
|
|
Imagine user Trong already upload image. So he is ready to submit. But for
|
|
|
|
the same time, he re-call API upload to upload another image too.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
So if API upload is finised first, which is kinda impossible (u know
|
|
|
|
upload file is not fast right?), everything right. But for most cases, API
|
|
|
|
submit is finished first. It means Trong's data is submitted with the old
|
|
|
|
image. Then API upload is finished, it will replace the old image with the
|
|
|
|
new one.So the old one, aka image in submitted data, is gone.
|
|
|
|
</p>
|
|
|
|
<p>Chaos right there!</p>
|
|
|
|
<p>
|
|
|
|
<strong>Solution</strong>: Use a lock, if user enter API upload, lock it
|
|
|
|
to prevent user call other APIs. Rememeber to unlock after finished
|
|
|
|
</p>
|
2023-03-05 08:48:43 +00:00
|
|
|
|
|
|
|
<div>
|
|
|
|
Feel free to ask me via
|
|
|
|
<a href="mailto:hauvipapro+posts@gmail.com">email</a> or
|
|
|
|
<a rel="me" href="https://hachyderm.io/@haunguyen">Mastodon</a>. Source
|
|
|
|
code is available on
|
|
|
|
<a href="https://github.com/haunt98/posts-go">GitHub</a>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|