Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openfaas-faas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Team Jaz CS 598 CCC Final Project
openfaas-faas
Commits
c2eb41ee
Commit
c2eb41ee
authored
7 years ago
by
Alex Ellis
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix buffer dead-lock in Watchdog (#33)
* Go sync group to handle blocking on buffered-pipes
parent
badcf786
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
watchdog/main.go
+53
-33
53 additions, 33 deletions
watchdog/main.go
with
53 additions
and
33 deletions
watchdog/main.go
+
53
−
33
View file @
c2eb41ee
...
...
@@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"strings"
"sync"
"time"
)
...
...
@@ -20,42 +21,61 @@ func (OsEnv) Getenv(key string) string {
return
os
.
Getenv
(
key
)
}
func
pipeRequest
(
config
*
WatchdogConfig
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
parts
:=
strings
.
Split
(
config
.
faasProcess
,
" "
)
targetCmd
:=
exec
.
Command
(
parts
[
0
],
parts
[
1
:
]
...
)
writer
,
_
:=
targetCmd
.
StdinPipe
()
var
out
[]
byte
var
err
error
var
res
[]
byte
var
wg
sync
.
WaitGroup
wg
.
Add
(
2
)
res
,
_
=
ioutil
.
ReadAll
(
r
.
Body
)
defer
r
.
Body
.
Close
()
go
func
()
{
defer
wg
.
Done
()
writer
.
Write
(
res
)
writer
.
Close
()
}()
go
func
()
{
defer
wg
.
Done
()
out
,
err
=
targetCmd
.
CombinedOutput
()
}()
wg
.
Wait
()
if
err
!=
nil
{
if
config
.
writeDebug
==
true
{
log
.
Println
(
targetCmd
,
err
)
}
w
.
WriteHeader
(
500
)
response
:=
bytes
.
NewBufferString
(
err
.
Error
())
w
.
Write
(
response
.
Bytes
())
return
}
if
config
.
writeDebug
==
true
{
os
.
Stdout
.
Write
(
out
)
}
// Match header for strict services
if
r
.
Header
.
Get
(
"Content-Type"
)
==
"application/json"
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
}
w
.
WriteHeader
(
200
)
w
.
Write
(
out
)
}
func
makeRequestHandler
(
config
*
WatchdogConfig
)
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
==
"POST"
{
parts
:=
strings
.
Split
(
config
.
faasProcess
,
" "
)
targetCmd
:=
exec
.
Command
(
parts
[
0
],
parts
[
1
:
]
...
)
writer
,
_
:=
targetCmd
.
StdinPipe
()
res
,
_
:=
ioutil
.
ReadAll
(
r
.
Body
)
defer
r
.
Body
.
Close
()
writer
.
Write
(
res
)
writer
.
Close
()
out
,
err
:=
targetCmd
.
CombinedOutput
()
if
err
!=
nil
{
if
config
.
writeDebug
==
true
{
log
.
Println
(
targetCmd
,
err
)
}
w
.
WriteHeader
(
500
)
response
:=
bytes
.
NewBufferString
(
err
.
Error
())
w
.
Write
(
response
.
Bytes
())
return
}
if
config
.
writeDebug
==
true
{
os
.
Stdout
.
Write
(
out
)
}
// Match header for strict services
if
r
.
Header
.
Get
(
"Content-Type"
)
==
"application/json"
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
}
w
.
WriteHeader
(
200
)
w
.
Write
(
out
)
pipeRequest
(
config
,
w
,
r
)
}
else
{
w
.
WriteHeader
(
http
.
StatusMethodNotAllowed
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment