Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
94040035
Commit
94040035
authored
Oct 20, 2020
by
Jacob Vosmaer
Committed by
Nick Thomas
Oct 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure error handling in main()
parent
8b157fd2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
27 deletions
+39
-27
changelogs/unreleased/jv-startup-errors.yml
changelogs/unreleased/jv-startup-errors.yml
+5
-0
logging.go
logging.go
+1
-1
main.go
main.go
+33
-26
No files found.
changelogs/unreleased/jv-startup-errors.yml
0 → 100644
View file @
94040035
---
title
:
Restructure error handling in main()
merge_request
:
633
author
:
type
:
fixed
logging.go
View file @
94040035
...
...
@@ -59,7 +59,7 @@ func startLogging(config logConfiguration) (io.Closer, error) {
// In text format, we use a separate logger for access logs
func
getAccessLogger
(
config
logConfiguration
)
(
*
log
.
Logger
,
io
.
Closer
,
error
)
{
if
config
.
logFormat
!=
"text"
{
return
log
.
StandardLogger
(),
nil
,
nil
return
log
.
StandardLogger
(),
ioutil
.
NopCloser
(
nil
)
,
nil
}
logFile
:=
config
.
logFile
...
...
main.go
View file @
94040035
...
...
@@ -81,9 +81,13 @@ func main() {
os
.
Exit
(
0
)
}
log
.
WithError
(
run
())
.
Fatal
(
"shutting down"
)
}
func
run
()
error
{
closer
,
err
:=
startLogging
(
logConfig
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"Unable to configure logger"
)
return
err
}
defer
closer
.
Close
()
...
...
@@ -91,12 +95,12 @@ func main() {
backendURL
,
err
:=
parseAuthBackend
(
*
authBackend
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"Invalid authBackend"
)
return
fmt
.
Errorf
(
"authBackend: %v"
,
err
)
}
cableBackendURL
,
err
:=
parseAuthBackend
(
*
cableBackend
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"Invalid cableBackend"
)
return
fmt
.
Errorf
(
"cableBackend: %v"
,
err
)
}
log
.
WithField
(
"version"
,
Version
)
.
WithField
(
"build_time"
,
BuildTime
)
.
Print
(
"Starting"
)
...
...
@@ -104,7 +108,7 @@ func main() {
// Good housekeeping for Unix sockets: unlink before binding
if
*
listenNetwork
==
"unix"
{
if
err
:=
os
.
Remove
(
*
listenAddr
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
log
.
WithError
(
err
)
.
Fatal
(
"Failed to remove socket"
)
return
err
}
}
...
...
@@ -113,32 +117,38 @@ func main() {
listener
,
err
:=
net
.
Listen
(
*
listenNetwork
,
*
listenAddr
)
syscall
.
Umask
(
oldUmask
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"Failed to listen"
)
return
fmt
.
Errorf
(
"main listener: %v"
,
err
)
}
finalErrors
:=
make
(
chan
error
)
// The profiler will only be activated by HTTP requests. HTTP
// requests can only reach the profiler if we start a listener. So by
// having no profiler HTTP listener by default, the profiler is
// effectively disabled by default.
if
*
pprofListenAddr
!=
""
{
go
func
()
{
err
:=
http
.
ListenAndServe
(
*
pprofListenAddr
,
nil
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"Failed to start pprof listener"
)
}
}()
l
,
err
:=
net
.
Listen
(
"tcp"
,
*
pprofListenAddr
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"pprofListenAddr: %v"
,
err
)
}
go
func
()
{
finalErrors
<-
http
.
Serve
(
l
,
nil
)
}()
}
monitoringOpts
:=
[]
monitoring
.
Option
{
monitoring
.
WithBuildInformation
(
Version
,
BuildTime
)}
if
*
prometheusListenAddr
!=
""
{
monitoringOpts
=
append
(
monitoringOpts
,
monitoring
.
WithListenerAddress
(
*
prometheusListenAddr
))
l
,
err
:=
net
.
Listen
(
"tcp"
,
*
prometheusListenAddr
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"prometheusListenAddr: %v"
,
err
)
}
monitoringOpts
=
append
(
monitoringOpts
,
monitoring
.
WithListener
(
l
))
}
go
func
()
{
err
:=
monitoring
.
Start
(
monitoringOpts
...
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"Failed to start monitoring"
)
// Unlike http.Serve, which always returns a non-nil error,
// monitoring.Start may return nil in which case we should not shut down.
if
err
:=
monitoring
.
Start
(
monitoringOpts
...
);
err
!=
nil
{
finalErrors
<-
err
}
}()
...
...
@@ -163,7 +173,7 @@ func main() {
if
*
configFile
!=
""
{
cfgFromFile
,
err
:=
config
.
LoadConfig
(
*
configFile
)
if
err
!=
nil
{
log
.
WithField
(
"configFile"
,
*
configFile
)
.
WithError
(
err
)
.
Fatal
(
"Can not load config file"
)
return
fmt
.
Errorf
(
"configFile: %v"
,
err
)
}
cfg
.
Redis
=
cfgFromFile
.
Redis
...
...
@@ -177,22 +187,19 @@ func main() {
err
=
cfg
.
RegisterGoCloudURLOpeners
()
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"could not load cloud credentials"
)
return
fmt
.
Errorf
(
"register cloud credentials: %v"
,
err
)
}
}
accessLogger
,
accessCloser
,
err
:=
getAccessLogger
(
logConfig
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"Unable to configure access logger"
)
}
if
accessCloser
!=
nil
{
defer
accessCloser
.
Close
()
return
fmt
.
Errorf
(
"configure access logger: %v"
,
err
)
}
defer
accessCloser
.
Close
()
up
:=
wrapRaven
(
upstream
.
NewUpstream
(
cfg
,
accessLogger
))
err
=
http
.
Serve
(
listener
,
up
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Fatal
(
"Unable to serve"
)
}
go
func
()
{
finalErrors
<-
http
.
Serve
(
listener
,
up
)
}()
return
<-
finalErrors
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment