Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

Ensure that interrupt signals are not relayed to the interrupt channel when the migration is over #25

Merged
merged 2 commits into from
Jan 23, 2017

Conversation

daddykotex
Copy link
Contributor

Hi,

Like I said here, I had a problem interrupting my program when a migration successfully ran. I think the problem was that the interrupt signals were still being relayed to the interrupt channel created in the Up method of migrate.go.

That channel is passed to the WaitAndRedirect function of the Pipe. I added a simple function that is called after the function return to ensure the signals stop being relayed when the migration is over, successful or not.

What do you think?
P.S. : I ran the test against a MySQL database where and everything was still fine.

Thanks, David

@mattes
Copy link
Owner

mattes commented Dec 30, 2014

Can you post the SQL migration files that are giving you trouble? I wasn't able to reproduce this behaviour myself.

@daddykotex
Copy link
Contributor Author

I'm going on a little trip, I will build a simple example so you can see
what was my problem and I'll provide it to you when I comeback.

Thanks
On 30 Dec 2014 16:08, "Matthias Kadenbach" notifications@github.com wrote:

Can you post the SQL migration files that are giving you trouble? I wasn't
able to reproduce this behaviour myself.

Reply to this email directly or view it on GitHub
#25 (comment).

@daddykotex
Copy link
Contributor Author

Take that simple main, where an application runs an Up migration and if everything is all right, set up a simple webserver on port 8080.

If no migration is ran, the application can quickly be terminated with ^C, but if a migration is ran successfully, it won't, ^C are ineffective.

package main

import (
    "github.com/mattes/migrate/migrate"
    "log"
    "net/http"
)

var driver = "mysql://root:@tcp(localhost:3306)/test"

type DummyHandler struct{}

func (dh DummyHandler) ServeHTTP(httpwriter http.ResponseWriter, httpRequest *http.Request) {
    httpwriter.Write([]byte("Hello World!"))
}

func main() {
    log.Println("Running")

    //I sync the database
    //If a migration is applied I cannot stop the web server with ^C
    //If no migration are ran, ^C works just fine

    allErrors, ok := migrate.UpSync(driver, ".")
    if !ok {
        log.Fatalln("An error has occured while syncing database", allErrors)
    } else {
        log.Println("DB Up done")
    }

    dummyHandler := new(DummyHandler)
    http.ListenAndServe(":8080", dummyHandler)
}

001_test.up.sql


CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `firstname` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) DEFAULT NULL,
  `active` tinyint(1) DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

001_test.down.sql

DROP TABLE IF EXISTS `users`;

@mattes
Copy link
Owner

mattes commented Feb 4, 2015

Hey @daddykotex! Sorry for my late reply. Whats the

 dummyHandler := new(DummyHandler)
 http.ListenAndServe(":8080", dummyHandler)

for?

@daddykotex
Copy link
Contributor Author

I use Migrate in a web server application, instead of bringing the whole code here I used that dummy handler to simulate when the problem occurs for me.

The app starts, run the migration and waits for request, like the little example here. If the migrations are ran against the database, I can't interrupt my server.

This whole dummy handler thing could be replaced with something like :

while(true){
     //do something here
}

@dbudworth
Copy link

for what it's worth, this happens to me as well
Ctrl-C doesn't work after a migration
I'm setting: migrate.NonGraceful() to avoid this issue

@dpetersen
Copy link

I'm seeing this too. Thanks for pointing out this workaround, @dbudworth. Same deal as the author of this issue, the migrations are running as part of the bootup of a web application.

@mattes mattes merged commit 0b3426b into mattes:master Jan 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants